Text recognition method and device, electronic equipment and storage medium
Through multi-dimensional conversion and processing of the original text, sequences of four different representation dimensions are generated, which solves the problem of single-dimensional feature extraction in the existing technology and achieves more accurate and comprehensive text recognition results.
Patent Information
- Application Number
- CN202410703840.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-27
AI Technical Summary
Existing text recognition technology can only extract single-dimensional features from the original text, resulting in inaccurate processing results.
By performing multi-dimensional transformation on the original text, sequences of four different representation dimensions (character sequences and word segmentation sequences) are generated and input into the pre-trained model for processing to comprehensively consider information of different dimensions.
It improves the accuracy and comprehensiveness of text recognition results and can better characterize the character and word segmentation features of text, thus improving the processing effect of subsequent text tasks.
Smart Images

Figure CN118709697A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a text recognition method, device, electronic device and storage medium. Background Art
[0002] With the development of computer technology, computer technology has been gradually applied to various daily education and learning activities, such as using computer technology to process text, thereby greatly saving human resources. Text recognition usually refers to performing various conversion operations on the original text to extract the text features corresponding to the original text, so as to facilitate the use of the extracted text features to perform various text tasks, such as text classification tasks, text prediction tasks, etc. Summary of the invention
[0003] The present disclosure provides a text recognition method, device, electronic device and storage medium to improve the accuracy of text recognition results.
[0004] In a first aspect, the present disclosure provides a text recognition method, comprising:
[0005] Converting a first character sequence of the original text to obtain a second character sequence;
[0006] Generate a first word segmentation sequence according to the word segmentations in the original text, and convert the first word segmentation sequence to obtain a second word segmentation sequence;
[0007] Generate a matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence, and the second word segmentation sequence;
[0008] The matrix sequence is input into a pre-trained text recognition model for processing to obtain a text recognition result.
[0009] In a second aspect, the present disclosure provides a text recognition device, comprising:
[0010] A character conversion module, adapted to convert a first character sequence of an original text to obtain a second character sequence; a word segmentation conversion module, adapted to generate a first word segmentation sequence according to the word segments in the original text, and convert the first word segmentation sequence to obtain a second word segmentation sequence;
[0011] A generating module, generating a matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence and the second word segmentation sequence;
[0012] The processing module is adapted to input the matrix sequence into a pre-trained text recognition model for processing to obtain a text recognition result.
[0013] In a third aspect, the present disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and the one or more computer programs are executed by the at least one processor so that the at least one processor can execute the above-mentioned text recognition method.
[0014] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned text recognition method when executed by a processor.
[0015] In a fifth aspect, the present disclosure provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned text recognition method.
[0016] The text recognition method provided by the embodiment of the present disclosure can convert the first character sequence of the original text to obtain the second character sequence, thereby comprehensively representing the character features of the original text through two different character sequences. In addition, the first word segmentation sequence and the second word segmentation sequence can be generated according to multiple word segments in the original text, thereby comprehensively representing the word segmentation features of the original text through two different word segmentation sequences. Correspondingly, a matrix sequence with more comprehensive information can be generated according to the above four sequences, and the matrix sequence is processed by a pre-trained model to make the final text recognition result more accurate. It can be seen that this method can comprehensively consider information of different dimensions by generating sequences of four different representation dimensions, thereby making the final text recognition result more comprehensive and accurate.
[0017] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings, in which:
[0019] Figure 1 A flowchart of a text recognition method provided by an embodiment of the present disclosure;
[0020] Figure 2A model structure diagram of a transformer model provided for an example of the present disclosure;
[0021] Figure 3 A schematic diagram of the structure of an attention module provided for an example of the present disclosure;
[0022] Figure 4 A flowchart of a text recognition method provided for an example of the present disclosure;
[0023] Figure 5 A block diagram of a text recognition device provided by an embodiment of the present disclosure;
[0024] Figure 6 A block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0026] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.
[0027] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0028] The terms used herein are only used to describe specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.
[0029] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined as such herein.
[0030] In the technical solution disclosed in this disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals. The use of user data in this technical solution complies with relevant national laws and regulations (for example, the "Information Security Technology Personal Information Security Specification", etc.). For example: corresponding prescribed measures are taken for personal information access control; prescribed restrictions are imposed on the display of personal information; the purpose of using personal information does not exceed the scope of direct or reasonable association; when using personal information, clear identity orientation is eliminated to avoid precise positioning of specific individuals.
[0031] Text recognition usually refers to: extracting text features corresponding to the original text by performing various conversion operations on the original text, so as to facilitate the use of the extracted text features to perform various text tasks, such as text classification tasks, text prediction tasks, etc. In related technologies, text recognition can usually only extract features of a single dimension in the original text, and there is a disadvantage that the processing results are not accurate enough. In order to solve the above problem, in this application, by generating a sequence of four different representation dimensions, information of different dimensions can be comprehensively considered, so that the final text recognition result is more comprehensive and accurate.
[0032] The text recognition method according to the embodiment of the present disclosure can be performed by an electronic device such as a terminal device or a server, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The server can be an independent physical server, a server cluster composed of multiple physical servers, or a cloud server capable of cloud computing. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory.
[0033] Figure 1 A flowchart of a text recognition method provided by an embodiment of the present disclosure. Figure 1 , the method comprising:
[0034] Step S110: converting the first character sequence of the original text to obtain a second character sequence.
[0035] The first character sequence is used to represent a plurality of text characters arranged in sequence in the original text. Generally, the character arrangement order of the second character sequence is different from that of the first character sequence.
[0036] The original text is the text to be processed, which may be a text sentence, a text paragraph, etc. The original text usually contains a plurality of text characters, and accordingly, the first character sequence of the original text is obtained according to the plurality of text characters of the original text.
[0037] Among them, the text characters in the original text can be either Chinese characters or English characters, and the present application does not limit the character types of the text characters. Accordingly, the first character sequence includes a plurality of characters that correspond one-to-one to the text characters in the original text. Specifically, the character types in the first character sequence can be the same as the character types of the text characters in the original text. Alternatively, the character types in the first character sequence can also be different from the character types of the text characters in the original text, and accordingly, the text characters in the original text are mapped to the characters in the first character sequence through a preset character mapping relationship. For example, in the case where the text characters in the original text are Chinese characters, the character types in the first character sequence can be various types of characters such as ASCII code characters or Arabic numeral characters, and the present application does not limit this.
[0038] In addition, in this step, it is necessary to convert the first character sequence to obtain the second character sequence. The conversion mainly includes character order conversion, as long as the character arrangement order of the second character sequence can be different from that of the first character sequence. For example, the second character sequence can be the inverse sequence of the first character sequence, that is, the character arrangement order of the second character sequence is opposite to that of the first character sequence.
[0039] Step S120: Generate a first word segmentation sequence according to the word segmentations in the original text, and perform conversion on the first word segmentation sequence to obtain a second word segmentation sequence.
[0040] Among them, a first segmentation sequence can be generated according to a plurality of segmentations arranged in order in the original text. The first segmentation sequence is used to characterize the types and quantities of a plurality of segmentations arranged in order in the original text. For example, the segmentation codes corresponding to different segmentations can be pre-set, and then the plurality of segmentation codes corresponding to the plurality of segmentations arranged in order can be combined into a first segmentation sequence, so as to characterize the characteristics of the segmentation dimension through the first segmentation sequence. Usually, the segmentation arrangement order of the second segmentation sequence is different from that of the first segmentation sequence. Accordingly, the first segmentation sequence can be further converted (for example, segmentation order conversion) to obtain a second segmentation sequence, so that the segmentation arrangement order of the second segmentation sequence is different from that of the first segmentation sequence.
[0041] In some optional implementations, the order of the segmentation words in the second segmentation sequence is opposite to the order of the segmentation words in the first segmentation sequence, that is, the second segmentation sequence is the inverse sequence of the first segmentation sequence.
[0042] In some other optional implementations, the first segmentation sequence can be generated in the following manner: first, the segmentation type of the segmentation is determined according to the segmentation length of the segmentation, and the segmentation description character of the segmentation is generated according to the segmentation type. Then, the segmentation description characters are sorted according to the arrangement order of the segmentation to obtain the first segmentation sequence. For example, multiple segmentation description characters of multiple segmentations can be sorted according to the arrangement order of multiple segmentations to obtain the first segmentation sequence. Among them, the segmentation type includes: an independent segmentation obtained by a single character, and a compound segmentation obtained by combining multiple characters. Among them, an independent segmentation usually contains only a single character, such as "I", "Is", etc., and a compound segmentation contains multiple characters, such as "park", "library", etc. The segmentation description character corresponding to the independent segmentation is usually a single independent description character. The segmentation description character corresponding to the compound segmentation of length N can include: N combined description characters, and each combined description character is used to represent the position information of the corresponding character in the compound segmentation; wherein the position information includes: the position of the head of the segmentation, the position of the tail of the segmentation, and the position of the middle of the segmentation. For example, the independent description character can be set to "O", and the combined description characters include: "B" for representing the first position of the word, "I" for representing the middle position of the word, and "E" for representing the tail position of the word. Correspondingly, if the original text is "I am in the library", the corresponding first word segmentation sequence is [O, O, B, I, E], and the second word segmentation sequence is [E, I, B, O, O].
[0043] Step S130: Generate a matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence and the second word segmentation sequence.
[0044] The first character sequence, the second character sequence, the first word segmentation sequence, and the second word segmentation sequence can be used as a sequence component in the matrix sequence, thereby forming a matrix sequence containing sequence features of four dimensions. Since the number of sequence components contained in the matrix sequence is four, the accuracy and comprehensiveness of text feature representation can be greatly improved compared with the conventional single sequence method.
[0045] Step S140: inputting the matrix sequence into the pre-trained text recognition model for processing to obtain a text recognition result.
[0046] The text recognition model may also be referred to as a pre-trained model below, and may specifically be various pre-trained deep learning models, such as transformer models. By processing the matrix sequence with the pre-trained model, a text recognition result can be obtained. The text recognition result can be used to implement various text recognition tasks, for example, the text recognition result can be used to implement various tasks such as text classification and text prediction. The text recognition model may also be a natural language processing model, and accordingly, the text recognition result can be used to characterize the semantic features of the original text.
[0047] It can be seen that the text recognition result mainly refers to: the output result obtained after the text recognition model processes the output content (i.e., the matrix sequence), and the output result can be used to characterize the semantic features of the original text. For example, the text recognition model can be used for tasks such as machine translation, text generation, sentiment analysis, and text summarization. The output result of the text recognition model is the above-mentioned text recognition result, and its specific content depends on the specific task and model architecture. Usually, the above-mentioned text recognition result can be a vector representation after encoding the original text, or it can be information such as semantic prediction made for the original text.
[0048] According to an embodiment of the present disclosure, it is possible to convert the first character sequence of the original text to obtain a second character sequence, thereby comprehensively representing the character features of the original text through two character sequences with different arrangement orders. In addition, it is possible to generate a first word segmentation sequence and a second word segmentation sequence based on multiple word segments in the original text, thereby comprehensively representing the word segmentation features of the original text through two word segmentation sequences with different arrangement orders. Correspondingly, a matrix sequence with more comprehensive information can be generated based on the above four sequences, and the matrix sequence is processed by a pre-trained model to make the final text recognition result more accurate. It can be seen that this method can comprehensively consider multiple dimensions such as arrangement order and word segmentation features by generating sequences of four different representation dimensions, thereby making the final text recognition result more comprehensive and accurate.
[0049] In addition, those skilled in the art may also make various modifications and variations to the method in this application:
[0050] In some optional implementations, the matrix sequence is a two-dimensional matrix sequence. In addition, the pre-trained model includes an attention module to implement feature extraction through the attention mechanism. Accordingly, the text recognition result can be obtained in the following manner:
[0051] First, an attention matrix corresponding to the two-dimensional matrix sequence is generated; wherein the attention matrix is a two-dimensional matrix. The attention matrix can be obtained by processing the two-dimensional matrix sequence in various ways such as character embedding, position encoding, and linear transformation.
[0052] Then, the model weight data generated by the pre-training model during the pre-training process is obtained, and the convolution weight matrix and the convolution kernel matrix corresponding to the attention matrix are determined according to the model weight data. Among them, the model weight data is generated during the pre-training process of the pre-training model, and is used to store various weight data required during the use of the model. For example, the model weight data can be stored in a preset model weight file, specifically used to store the convolution weights corresponding to different characters. Correspondingly, the values of multiple matrix elements in the convolution weight matrix can be determined according to the convolution weights corresponding to the multiple matrix characters in the attention matrix. The so-called convolution weight refers to: the weight used in the process of performing weighted convolution operations on the attention matrix using the convolution kernel, and the weight ratio of each element in the convolution kernel can be adjusted through the convolution weight. The convolution kernel matrix can be a convolution kernel matrix of preset dimensions, for example, it can be a 2*2 convolution kernel matrix.
[0053] Finally, a weighted convolution operation is performed on the attention matrix through the convolution weight matrix and the convolution kernel matrix to obtain a feature extraction matrix corresponding to the attention matrix; and the text recognition result is determined according to the feature extraction matrix. Among them, unlike the conventional convolution operation, the convolution operation in this application is a weighted convolution operation with weights, and because the convolution weights are gradually optimized during the training process of the pre-trained model as the model is iteratively updated, the accuracy of feature extraction can be further improved.
[0054] In some optional implementations, before performing weighted convolution operations on the attention matrix through the convolution weight matrix and the convolution kernel matrix, mask processing can also be performed on the attention matrix in advance to obtain the processed attention matrix. Accordingly, when performing weighted convolution operations on the attention matrix through the convolution weight matrix and the convolution kernel matrix, weighted convolution operations are specifically performed on the attention matrix after mask processing. In specific implementation, the mask weight matrix corresponding to the attention matrix can be first determined according to the model weight data; the attention matrix is subjected to mask weight processing through the mask weight matrix to obtain the processed attention matrix. Among them, the model weight data is further used to store the mask weights corresponding to different characters, and accordingly, the values of multiple matrix elements in the mask weight matrix can be determined according to the mask weights corresponding to the multiple matrix characters in the attention matrix. It can be seen that in the pre-training process of the pre-training model, the mask weight corresponding to each character is obtained by training the character separately. Therefore, by querying the model weight data, the mask weight matrix corresponding to the attention matrix can be determined. It can be seen that the mask weight matrix is used to reflect the importance of each character in the attention matrix. For example, the more important the character is, the greater the corresponding weight value in the mask weight matrix; and the less important the character is, the smaller the corresponding weight value in the mask weight matrix. With the help of mask weight processing, the important characters in the processed attention matrix can have a greater weight, which is conducive to enhancing the role of important characters in the subsequent processing process.
[0055] In some optional implementations, the pre-trained model (i.e., the text recognition model) includes an attention module, and the attention module includes: a mask submodule, and a normalization submodule connected to the output end of the mask submodule. Correspondingly, in the above process, the attention matrix is subjected to mask weight processing through the mask submodule to obtain the processed attention matrix. In addition, a weighted convolution operation is performed on the attention matrix through the normalization submodule to obtain a weighted convolution operation result; the weighted convolution operation result is normalized to obtain a feature extraction matrix corresponding to the attention matrix. It can be seen that this embodiment focuses on optimizing the mask submodule and the normalization submodule in the attention module.
[0056] In some optional implementations, the model weight data is used to store convolution weights and mask weights corresponding to different characters; accordingly, the multiple matrix element values in the convolution weight matrix can be determined according to the convolution weights corresponding to the multiple matrix characters in the attention matrix; the multiple matrix element values in the mask weight matrix can be determined according to the mask weights corresponding to the multiple matrix characters in the attention matrix.
[0057] In some optional implementations, the convolution weights and mask weights corresponding to different characters stored in the model weight data can be determined in the following manner: in the i-th round of pre-training of the text recognition model, the i-th loss value of the model loss function is calculated according to the i-th convolution weight value and the i-th mask weight value; when the i-th loss value does not meet the preset convergence condition, the text recognition model is updated for the i-th time according to the i-th loss value, and the i+1-th round of pre-training is performed according to the i+1-th convolution weight value and the i+1-th mask weight value obtained after the i-th update, until the loss value of the model loss function meets the preset convergence condition; wherein i is a natural number.
[0058] Specifically, in the i-th round of pre-training of the pre-trained model, the i-th loss value of the model loss function is calculated according to the i-th convolution weight value of the convolution weights corresponding to different characters and the i-th mask weight value of the mask weight; when the i-th loss value does not meet the preset convergence condition, the pre-trained model is updated for the i-th time according to the i-th loss value, and the i+1-th round of pre-training is performed according to the i+1-th convolution weight value of the convolution weight obtained after the i-th update and the i+1-th mask weight value of the mask weight, until the loss value of the model loss function meets the preset convergence condition; wherein, the i+1-th convolution weight value of the convolution weight and the i+1-th mask weight value of the mask weight can be understood as being obtained during the i-th update process of the text recognition model. It can be seen that in the present application, the convolution weight value of the convolution weight and the mask weight value of the mask weight are continuously updated with the update iteration during the model pre-training process. Specifically, the convolution weight value of the convolution weight and the mask weight value of the mask weight can be used as partial parameters in the model loss function, respectively. Correspondingly, since the model needs to perform derivative operations on the model loss function and propagate errors during the update and iteration process, the convolution weight values of the convolution weights and the mask weight values of the mask weights will be updated together during the update and iteration process of the model. Through multiple update iterations, it can be ensured that the final convolution weight values of the convolution weights and the mask weight values of the mask weights meet business requirements. Among them, when i is equal to 1, the first convolution weight value of the convolution weight and the first mask weight value of the mask weight can be set to the default initial value, or can be set randomly. In short, the present application does not limit the initial assignment method of the weights, as long as the final weights can become reasonable with the iteration of the model.
[0059] For ease of understanding, the technical implementation details in the above embodiment are described in detail below using a specific example:
[0060] As an important technology used in the field of NLP, pre-trained models play an important role in the process of natural language processing and play an important role in character-level encoding. They have played a good role and effect in many natural language processing tasks. Accordingly, the improvement of the transformer model has also become an important research direction.
[0061] In this example, in order to improve the output accuracy of the transformer model, two aspects of improvement were mainly performed: on the one hand, a multi-dimensional conversion process was performed on the original text, thereby obtaining feature sequences of multiple different dimensions, so that the input data of the transformer model was expanded from single-dimensional sequence data to multi-dimensional matrix data, thereby enriching the feature types of the data and helping to improve the accuracy of subsequent processing. On the other hand, improvements were made to the attention module in the transformer model, focusing on the mask submodule and normalization submodule in the attention module. By adding weight operations and convolution operations, the pertinence and accuracy of feature extraction were improved.
[0062] Figure 2 The model structure diagram of the transformer model in this example is shown. Figure 2 As shown, the transformer model in this example may include: an attention module (specifically, a multi attention module), a linear propagation layer (specifically, a Linear Forward module), and a residual connection layer (specifically, an add&norm module).
[0063] Figure 3 The structural diagram of the attention module is shown in Figure 3 As shown, the attention module further includes: a first tensor multiplication submodule (for example, it can be a MatMul submodule), a normalization submodule (for example, it can be a Scale submodule), a mask submodule (for example, it can be a Mask submodule), a normalization submodule (for example, it can be a softmax submodule) and a second tensor multiplication submodule.
[0064] Figure 4 A flowchart of the text recognition method in this example is shown. Figure 4 As shown, the method comprises the following steps:
[0065] Step S401: Obtain a second character sequence according to a first character sequence of an original text.
[0066] Specifically, the character string sequence of the original text is processed and converted into an encoded data sequence (ie, a first character sequence), which is then deserialized to obtain a second character sequence.
[0067] Step S402: obtaining a second word segmentation sequence according to the first word segmentation sequence of the original text, and generating a two-dimensional matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence and the second word segmentation sequence.
[0068] The word segmentation information of the string is encoded, and the corresponding word head is B, the word middle is I, and the word tail is E. The first word segmentation sequence is obtained according to the encoding result, and then the first word segmentation sequence is reversed to obtain the second word segmentation sequence. , which are spliced together as the sequence features of the word segmentation.
[0069] The above four sequences are concatenated together to obtain a two-dimensional matrix of len(sent)×4, where len(sent) represents the length of the string. This two-dimensional matrix is a two-dimensional matrix sequence.
[0070] It can be seen that compared with the conventional method, this example always carries the sequence features of positive and reverse order from input to subsequent mapping process, and also incorporates the positive and reverse order features of word segmentation, thereby ensuring that subsequent results carry more features, thereby improving the accuracy of processing.
[0071] Step S403: Generate an attention matrix corresponding to the two-dimensional matrix sequence.
[0072] Specifically, the two-dimensional matrix sequence is input into the transformer model, and accordingly, the two-dimensional matrix sequence is processed by the transformer model. Furthermore, an attention matrix corresponding to the two-dimensional matrix sequence is generated by the attention module.
[0073] like Figure 3 As shown, first, a first input component, a second input component and a third input component corresponding to a two-dimensional matrix sequence are generated, and the first input component and the second input component are input into a first tensor multiplication submodule, and after being processed by a normalization submodule, the above-mentioned attention matrix is obtained.
[0074] Among them, the first input component, the second input component and the third input component can be the Q (Query) component, K (Key) component and V (Value) component in the attention mechanism respectively. Among them, in deep learning and natural language processing (NLP), the Q (Query) component, the K (Key) component and the V (Value) component are the core components of the attention mechanism. The above components can also be called vectors, which can be obtained by performing a series of transformations and embeddings on the two-dimensional matrix sequence. For example, the input components corresponding to the two-dimensional matrix sequence can be generated by various methods such as character embedding, position encoding and linear transformation.
[0075] Accordingly, the first input component and the second input component can be input into Figure 3 The first tensor multiplication submodule in is used to realize the multiplication operation between the two input tensors. Then, the output result of the first tensor multiplication submodule is input to the standardization submodule to realize the standardization of the multiplication result, thereby obtaining the above-mentioned attention matrix. It can be seen that the attention matrix is obtained by a series of processing of the two-dimensional matrix sequence by the attention module, and the purpose is to more accurately extract the features in the two-dimensional matrix sequence through the attention mechanism.
[0076] Step S404: Obtain the model weight file generated by the pre-training model during the pre-training process, and determine the mask weight matrix corresponding to the attention matrix according to the model weight file; perform mask weight processing on the attention matrix through the mask weight matrix to obtain the processed attention matrix.
[0077] Specifically, this step can be done by Figure 3 The mask submodule in is executed. Among them, the model weight file is used to store various weight parameters in the pre-trained model, and the above weight parameters are gradually determined during the update process of the pre-trained model. Specifically, the model weight file is used to store the mask weights corresponding to different characters, and the multiple matrix element values in the mask weight matrix are determined according to the mask weights corresponding to the multiple matrix characters in the attention matrix. Correspondingly, the attention matrix is subjected to mask weight processing through the mask weight matrix to obtain the processed attention matrix. Since a plurality of different mask weight values are recorded in the mask weight matrix, the importance of characters at different positions can be represented by different mask weight values, thereby ensuring that the important characters in the processed attention matrix have greater weights, thereby enhancing the importance of important characters in the subsequent processing process.
[0078] In a specific example, assuming that the character length of the original text is N, accordingly, after step S401, a first character sequence of length N and a second character sequence of length N are obtained. And, after step S402, a first word segmentation sequence of length N and a second word segmentation sequence of length N are obtained. Correspondingly, the final attention matrix can be a 4*N two-dimensional matrix, which contains 4 vector components, and each vector component corresponds to one of the above sequences. It can be seen that the length of each vector component in the attention matrix is the same and corresponds to the same original text. In this case, the mask weight matrix can be a 1*N matrix or vector, and it can be seen that the N weight values in the mask weight matrix correspond to the N vector elements in each vector component one by one, so each weight value in the mask weight matrix is used to characterize the importance of its corresponding vector element. The vector element is obtained by converting the text characters in the original text, so each weight value in the mask weight matrix can indirectly characterize the importance of each text character in the original text. As a result, more attention can be given to characters with high importance in the subsequent operation process. For example, if the original text is "I am in the library", a higher mask weight may be set for the three characters "library". The mask weights corresponding to different characters stored in the model weight file are determined based on multiple factors such as the frequency and position of the character during the training process.
[0079] It can be seen that the processed attention matrix obtained by performing mask weight processing on the attention matrix through the mask weight matrix can make more important matrix elements have higher weight values.
[0080] In the specific implementation, in the mask stage, the mask weight (i.e. weight-mask) mentioned above can be used for weight processing. The calculation formula of the mask weight matrix can be weight1×[1…1] T , where weight1 can be a randomly assigned mask weight matrix in the initial training stage of the pre-trained model, and it is integrated into the subsequent training process so that the mask features can adapt to the corresponding sequence results during the training process, so that different texts have different mask features. Wherein, weight1 can be used as a parameter in the model loss function. Accordingly, in the update and iteration process of the pre-trained model, by taking the gradient derivative of the loss function, the model is updated in the direction of reducing the loss value, and weight1 can be continuously optimized. For example, the cross entropy loss function can be used to perform reverse training optimization on the entire network.
[0081] Step S405: Determine the convolution weight matrix and the convolution kernel matrix corresponding to the attention matrix according to the model weight file; perform weighted convolution operation on the attention matrix through the convolution weight matrix and the convolution kernel matrix to obtain a feature extraction matrix corresponding to the attention matrix.
[0082] Specifically, this step can be done by Figure 3 The normalization submodule in is executed. Among them, the model weight file is used to store the convolution weights corresponding to different characters. Correspondingly, the values of multiple matrix elements in the convolution weight matrix are determined according to the convolution weights corresponding to multiple matrix characters in the attention matrix. It can be seen that in the pre-training process of the model, the convolution weights corresponding to various character elements have been predetermined. Therefore, by querying the model weight file, the convolution weight matrix and the convolution kernel matrix corresponding to the attention matrix can be automatically generated.
[0083] Among them, the convolution kernel matrix can be a matrix of fixed values or a matrix of variable values. This application does not impose any limitation on this, as long as convolution feature extraction can be achieved.
[0084] Among them, the convolution weight matrix can be represented by weight2, and each convolution element value in the convolution kernel matrix can be represented by conv val[i,j] Indicates that i and j represent the convolution element values in the i-th row and j-th column of the convolution kernel matrix. Correspondingly, the process of weighted convolution operation on the attention matrix can be realized by the following formula:
[0085] Among them, conv val[i,j] Represents the value of the convolution element in the i-th row and j-th column of the convolution kernel; weight2 represents the convolution weight. For example, weight2[i,j] represents the convolution weight value in the i-th row and j-th column of the convolution weight matrix. QK[s,n] represents the value of the matrix element in the s-th row and n-th column of the attention matrix. It can be seen that through the above formula, the purpose of performing weighted convolution operation on the attention matrix through the convolution weight matrix and the convolution kernel matrix can be achieved to obtain the feature extraction matrix corresponding to the attention matrix.
[0086] Since this example performs multi-dimensional processing on the original text, thus forming a two-dimensional matrix (different from the single vector in the conventional method), the design of the convolution module can accurately capture more information and finally feed it back to the entire network. At the same time, the use of the weighted softmax matrix (i.e., the attention matrix) can better learn the characteristics of each module in the subsequent process, making the effect of the attention mechanism more prominent.
[0087] Step S406: Determine the text recognition result according to the feature extraction matrix.
[0088] Specifically, this step can be done by Figure 3 The second tensor multiplication submodule in is executed. Accordingly, the second tensor multiplication submodule extracts the feature matrix and combines the third input component to obtain the output result of the attention module. And the output result of the attention module will be further provided to Figure 2 The linear propagation layer and the residual connection layer in are used to obtain the final text recognition result.
[0089] In summary, the above method not only analyzes and extracts features for specific text sequences, but also extracts features at the levels of semantics related to the reverse order and word segmentation. It can better extract existing text features and finally obtain corresponding semantic information. It can also extract more accurate character vectors for each character.
[0090] Moreover, analyzing and extracting text sequences from a two-dimensional level rather than a one-dimensional sequence level can more effectively obtain the relationship between texts and the relationship within texts. Moreover, extracting across the relationship between the previous and next sequences can obtain information with a higher information dimension, which has a positive effect on tasks that may use character vectors later. Among them, the most important attention module in the transformer model is improved, so that further semantic information can be obtained, and finally on this basis it can be applied to downstream tasks, such as text classification and other specific tasks.
[0091] In short, this example not only considers the sequence information of the text itself, but also takes into account the reverse information that may exist in the sequence of the text. Because in many tasks, the result of the current character is not only related to the previous character, but also to the following character, so this design can effectively consider the context. The word segmentation information is also considered into the encoding, and the word segmentation and the original sequence of the text are spliced, so that the relationship between sentences can be obtained, and finally the higher-level implicit information can be obtained. In addition, the text data is feature extracted at the two-dimensional level, so that the two-dimensional features of the syntax are extracted, instead of simply inputting the one-dimensional sequence features, in which the relationship between characters and the relationship between two characters and words, as well as the relationship between forward words and reverse words can be fully considered. It can be seen that this example provides a method for improving transformers by extracting text information in a multi-dimensional way. Among them, multi-dimensionality refers to multi-dimensionality in semantic extraction, not just using a sequence for extraction in the traditional transformer package (this method only simply processes and extracts the semantic sequence before and after, and cannot obtain further information).
[0092] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.
[0093] In addition, the present disclosure also provides a text recognition device, an electronic device, and a computer-readable storage medium, all of which can be used to implement any text recognition method provided by the present disclosure. The corresponding technical solutions and descriptions are referred to in the corresponding records of the method part and will not be repeated here.
[0094] Figure 5 A block diagram of a text recognition device provided in an embodiment of the present disclosure.
[0095] Reference Figure 5 , the present disclosure embodiment provides a text recognition device 50, the text recognition device comprising:
[0096] A character conversion module 51, adapted to convert a first character sequence of an original text to obtain a second character sequence;
[0097] A word segmentation conversion module 52, adapted to generate a first word segmentation sequence according to the word segments in the original text, and convert the first word segmentation sequence to obtain a second word segmentation sequence;
[0098] A generating module 53 generates a matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence and the second word segmentation sequence;
[0099] The processing module 54 is adapted to input the matrix sequence into a pre-trained text recognition model for processing to obtain a text recognition result.
[0100] In an optional implementation, the character arrangement order of the second character sequence is opposite to the character arrangement order of the first character sequence; the word arrangement order of the second word segmentation sequence is opposite to the word arrangement order of the first word segmentation sequence;
[0101] The step of generating a first word segmentation sequence according to the plurality of word segments arranged in sequence in the original text includes:
[0102] Determining the segmentation type of the segmentation according to the segmentation length of the segmentation, and generating the segmentation description character of the segmentation according to the segmentation type; wherein the segmentation type includes: an independent segmentation obtained by a single character, and a compound segmentation obtained by combining multiple characters;
[0103] Sort the multiple word segmentation description characters of the multiple word segmentations according to the arrangement order of the multiple word segmentations to obtain the first word segmentation sequence;
[0104] Among them, the segmentation description character corresponding to the independent segmentation is a single independent description character; the segmentation description character corresponding to the compound segmentation of length N includes: N combined description characters, and each combined description character is used to represent the position information of the corresponding character in the compound segmentation; wherein the position information includes: the segmentation head position, the segmentation tail position and the segmentation middle position.
[0105] In an optional implementation manner, the matrix sequence is a two-dimensional matrix sequence; then the processing module is specifically adapted to:
[0106] Generate an attention matrix corresponding to the two-dimensional matrix sequence; wherein the attention matrix is a two-dimensional matrix;
[0107] Obtain model weight data generated by the pre-training model during the pre-training process, and determine a convolution weight matrix and a convolution kernel matrix corresponding to the attention matrix according to the model weight data;
[0108] Performing a weighted convolution operation on the attention matrix through the convolution weight matrix and the convolution kernel matrix to obtain a feature extraction matrix corresponding to the attention matrix;
[0109] The text recognition result is determined according to the feature extraction matrix.
[0110] In an optional implementation, the processing module is further adapted to:
[0111] Determine a mask weight matrix corresponding to the attention matrix according to the model weight data;
[0112] The attention matrix is subjected to mask weight processing through the mask weight matrix to obtain a processed attention matrix.
[0113] In an optional implementation, the text recognition model includes an attention module, and the attention module includes: a mask submodule, and a normalization submodule connected to an output end of the mask submodule;
[0114] Then the performing mask weight processing on the attention matrix to obtain the processed attention matrix includes: performing mask weight processing on the attention matrix through the mask submodule to obtain the processed attention matrix;
[0115] Furthermore, performing a weighted convolution operation on the attention matrix to obtain a feature extraction matrix corresponding to the attention matrix includes: performing a weighted convolution operation on the attention matrix through the normalization submodule to obtain a weighted convolution operation result; and performing normalization processing on the weighted convolution operation result to obtain a feature extraction matrix corresponding to the attention matrix.
[0116] In an optional implementation, the model weight data is used to store convolution weights and mask weights corresponding to different characters;
[0117] Then the values of multiple matrix elements in the convolution weight matrix are determined according to the convolution weights corresponding to the multiple matrix characters in the attention matrix;
[0118] The values of multiple matrix elements in the mask weight matrix are determined according to the mask weights corresponding to the multiple matrix characters in the attention matrix.
[0119] In an optional implementation, the convolution weights and mask weights corresponding to different characters stored in the model weight data are determined in the following manner:
[0120] In the i-th round of pre-training of the text recognition model, according to the i-th convolution weight value and the i-th mask weight value, calculating the i-th loss value of the model loss function;
[0121] When the i-th loss value does not meet the preset convergence condition, the text recognition model is updated for the i-th time according to the i-th loss value, and the i+1-th round of pre-training process is performed according to the i+1-th convolution weight value and the i+1-th mask weight value obtained after the i-th update, until the loss value of the model loss function meets the preset convergence condition; wherein i is a natural number.
[0122] Each module in the above-mentioned text recognition device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0123] Figure 6 A block diagram of an electronic device provided in an embodiment of the present disclosure.
[0124] Reference Figure 6An embodiment of the present disclosure provides an electronic device, which includes: at least one processor 701; at least one memory 702, and one or more I / O interfaces 703, connected between the processor 701 and the memory 702; wherein the memory 702 stores one or more computer programs that can be executed by the at least one processor 701, and the one or more computer programs are executed by the at least one processor 701 so that the at least one processor 701 can execute the above-mentioned text recognition method.
[0125] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0126] The present disclosure also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the above method when executed by a processor / processing core. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.
[0127] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned text recognition method.
[0128] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).
[0129] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.
[0130] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0131] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0132] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0133] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0134] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0135] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0136] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0137] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present disclosure as set forth in the appended claims.
Claims
1. A text recognition method, characterized in that: include: Converting a first character sequence of the original text to obtain a second character sequence; Generate a first word segmentation sequence according to the word segmentations in the original text, and convert the first word segmentation sequence to obtain a second word segmentation sequence; Generate a matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence, and the second word segmentation sequence; The matrix sequence is input into a pre-trained text recognition model for processing to obtain a text recognition result.
2. The method according to claim 1, characterized in that The step of generating a first word segmentation sequence according to the word segmentations in the original text includes: Determining the segmentation type of the segmentation according to the segmentation length of the segmentation, and generating segmentation description characters of the segmentation according to the segmentation type; The word segmentation description characters are sorted according to the arrangement order of the word segmentations to obtain the first word segmentation sequence.
3. The method according to claim 1, characterized in that The matrix sequence is a two-dimensional matrix sequence; the matrix sequence is input into a pre-trained text recognition model for processing to obtain a text recognition result, which includes: Generate an attention matrix corresponding to the two-dimensional matrix sequence; wherein the attention matrix is a two-dimensional matrix; Obtain model weight data generated by the text recognition model during the pre-training process, and determine a convolution weight matrix and a convolution kernel matrix corresponding to the attention matrix according to the model weight data; Performing a weighted convolution operation on the attention matrix through the convolution weight matrix and the convolution kernel matrix to obtain a feature extraction matrix corresponding to the attention matrix; The text recognition result is determined according to the feature extraction matrix.
4. The method according to claim 3, characterized in that Before performing weighted convolution operation on the attention matrix through the convolution weight matrix and the convolution kernel matrix, the method further includes: Determine a mask weight matrix corresponding to the attention matrix according to the model weight data; The attention matrix is subjected to mask weight processing through the mask weight matrix to obtain a processed attention matrix.
5. The method according to claim 4, characterized in that The text recognition model includes an attention module, and the attention module includes: a mask submodule, and a normalization submodule connected to the output end of the mask submodule; the mask weight processing is performed on the attention matrix to obtain the processed attention matrix, including: Through the mask submodule, the attention matrix is subjected to mask weight processing to obtain a processed attention matrix; The weighted convolution operation is performed on the attention matrix to obtain a feature extraction matrix corresponding to the attention matrix, comprising: Through the normalization submodule, a weighted convolution operation is performed on the attention matrix to obtain a weighted convolution operation result; the weighted convolution operation result is normalized to obtain a feature extraction matrix corresponding to the attention matrix.
6. The method according to any one of claims 3 to 5, characterized in that: The model weight data is used to store convolution weights and mask weights corresponding to different characters; Then the values of multiple matrix elements in the convolution weight matrix are determined according to the convolution weights corresponding to the multiple matrix characters in the attention matrix; The values of multiple matrix elements in the mask weight matrix are determined according to the mask weights corresponding to the multiple matrix characters in the attention matrix.
7. The method according to claim 6, characterized in that The convolution weights and mask weights corresponding to different characters stored in the model weight data are determined in the following manner: In the i-th round of pre-training of the text recognition model, according to the i-th convolution weight value and the i-th mask weight value, calculating the i-th loss value of the model loss function; When the i-th loss value does not meet the preset convergence condition, the text recognition model is updated for the i-th time according to the i-th loss value, and the i+1-th round of pre-training process is performed according to the i+1-th convolution weight value and the i+1-th mask weight value obtained after the i-th update, until the loss value of the model loss function meets the preset convergence condition; wherein i is a natural number.
8. A text recognition device, characterized in that: include: A character conversion module, adapted to convert a first character sequence of an original text to obtain a second character sequence; A word segmentation conversion module, adapted to generate a first word segmentation sequence according to the word segments in the original text, and convert the first word segmentation sequence to obtain a second word segmentation sequence; A generating module, generating a matrix sequence according to the first character sequence, the second character sequence, the first word segmentation sequence and the second word segmentation sequence; The processing module is adapted to input the matrix sequence into a pre-trained text recognition model for processing to obtain a text recognition result.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs executable by the at least one processor, and the one or more computer programs are executed by the at least one processor to enable the at least one processor to perform the text recognition method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the text recognition method according to any one of claims 1 to 7.
11. A computer program product, characterized in that The invention comprises a computer-readable code or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the text recognition method according to any one of claims 1 to 7.
