Multilingual text detection and correction method and system, electronic device and storage medium

By using multilingual character recognition and artificial intelligence models for spelling and semantic detection, the problem of spelling and semantic errors in cross-language texts has been solved, achieving efficient error correction.

CN114282527BActive Publication Date: 2026-03-17CHINA SCI & TECH INTERNET BEIJING INFORMATION TECH +2
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-22
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing error correction technologies cannot effectively handle spelling and semantic errors in cross-language texts, especially foreign characters appearing in Chinese contexts, leading to semantic misunderstandings.

Method used

By using multilingual character recognition, language detection, spelling detection, and semantic detection, combined with artificial intelligence models, spelling and semantic errors are corrected, and corresponding error correction methods are adopted for errors in different languages.

Benefits of technology

It improves the efficiency of cross-language text error correction, enabling a better understanding of text semantics in cross-language contexts and accurate correction of detected erroneous words.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114282527B_ABST
    Figure CN114282527B_ABST
Patent Text Reader

Abstract

The application provides a multilingual text detection and correction method and system, electronic equipment and storage medium. The method comprises: acquiring a text to be detected, and performing multilingual character recognition on the text to be detected to obtain at least one sentence to be recognized; performing language detection on characters of a target language in the sentence to be recognized to obtain words to be detected, and performing spelling detection and semantic detection on the words to be detected; and if at least one of the words to be detected has spelling errors and / or semantic errors, performing corresponding spelling correction and / or semantic correction on the words having spelling errors and / or semantic errors. The application can better understand the text semantics in a cross-language context, and detect all characters of a target language in the text and correct only the words having errors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and particularly to a method, system, electronic device and storage medium for multi-language text detection and error correction. Background Art

[0002] Some existing error correction technical solutions, whether rule-based or neural network-based, can only correct texts with a single language background and do not consider the situation of code conversion. For example, "小张真是个gafe" (Spanish slang: unlucky guy). Based on the foreign characters that appear in the Chinese context, there may be spelling mistakes and semantic errors, resulting in the problem of semantic understanding errors of cross-language texts in the system. Summary of the Invention

[0003] The present invention provides a method, system, electronic device and storage medium for multi-language text detection and error correction to solve the problem of speech understanding errors of cross-language texts in the prior art.

[0004] In a first aspect, the present invention provides a method for multi-language text detection and error correction, the method comprising:

[0005] Obtain a text to be detected, and perform multi-language character recognition on the text to be detected to obtain at least one statement to be recognized, the statement to be recognized comprising characters of a main language and characters of at least one target language, the main language being different from the target language;

[0006] Perform language detection on the characters of the target language in the statement to be recognized to obtain words in a language to be detected, and perform spelling detection and semantic detection on the words in the language to be detected;

[0007] If at least one of the words in the language to be detected has a spelling mistake and / or a semantic mistake, perform corresponding spelling correction and / or semantic correction on the word having the spelling mistake and / or the semantic mistake.

[0008] In an embodiment of the present invention, the obtaining a text to be detected and performing multi-language character recognition on the text to be detected to obtain at least one statement to be recognized comprises:

[0009] Perform data cleaning on the text to be detected to delete illegal characters and garbled characters caused by encoding errors in the text to be detected;

[0010] Perform sentence splitting on the text to be detected to obtain the at least one statement to be recognized, and delete the blank characters at the beginning and end of each statement to be recognized;

[0011] The characters in the statement to be recognized are identified, and if characters of the target language are present, the position of the characters of the target language in the statement to be recognized is recorded.

[0012] In one embodiment of the present invention, the language detection of the characters of the target language in the statement to be identified includes:

[0013] Input the sentence to be recognized containing characters of the target language into the preset language detection model;

[0014] The preset language detection model segments the input sentence to be identified based on a sequence labeling mechanism and outputs the language corresponding to the target language words present in the sentence to be identified.

[0015] In one embodiment of the present invention, the preset language detection model performs word segmentation on the input sentence to be identified based on a sequence labeling mechanism, and outputs the language corresponding to the target language words present in the sentence to be identified, including:

[0016] The sentence to be identified is segmented into words to obtain a word segmentation list with at least one word, and preset special characters are added to the beginning and end of the word segmentation list to indicate the start and end;

[0017] Map each word in the word segmentation list to its corresponding identifier to obtain an identifier list;

[0018] The list of identifiers is input into the embedding layer of the preset language detection model to convert it into a first matrix with a first preset dimension;

[0019] The first matrix is ​​input into the multi-layer transformer of the preset language detection model for calculation, so as to output a second matrix with a second preset dimension;

[0020] The second matrix is ​​input into the fully connected layer of the preset language detection model, and the output of the fully connected layer is normalized to obtain the language probability of each word segment corresponding to each identifier.

[0021] The language of each word segment is determined based on its language probability.

[0022] In one embodiment of the present invention, the spelling detection and semantic detection are performed on the words in the language to be detected:

[0023] Each word in the language to be detected is input into a preset spelling detection model to detect whether there are spelling errors;

[0024] If the preset spelling detection model detects that there are no spelling errors in each of the words in the language to be detected, then the sentence to be detected containing at least one word in the language to be detected is input into the preset semantic detection model to detect whether there are semantic errors.

[0025] If the statement to be detected does not have semantic errors, then the text to be detected corresponding to the statement to be detected will be returned as the detected text.

[0026] In one embodiment of the present invention, if at least one word in the language to be detected has a spelling error and / or a semantic error, then performing corresponding spelling correction and / or semantic correction on the word with the spelling error and / or semantic error includes:

[0027] If the word in the language to be detected has a spelling error, the word in the language to be detected is input into a preset spelling correction model for spelling correction processing.

[0028] The sentence to be detected, which contains words of the language to be detected that have undergone spell correction, is input into the preset semantic detection model to detect whether there are semantic errors.

[0029] If the statement to be detected does not have semantic errors, then the text to be detected corresponding to the spell-corrected statement to be detected will be returned as the detected text.

[0030] In one embodiment of the present invention, if at least one word in the language to be detected has a spelling error and / or a semantic error, then performing corresponding spelling correction and / or semantic correction on the word with the spelling error and / or semantic error includes:

[0031] If the statement to be detected contains a semantic error, the statement to be detected is input into a preset semantic error correction model for semantic error correction processing.

[0032] The text to be detected corresponding to the semantically corrected statement to be detected is returned as the detected text.

[0033] In one embodiment of the present invention, before inputting each of the words in the language to be detected into a preset spelling detection model to detect whether there is a spelling error, the method further includes:

[0034] A preset number of reference language words are input into the encoder of the preset spelling detection model for encoding processing. The preset number of reference language words includes a set of correctly spelled words and a set of incorrectly spelled words that have been labeled.

[0035] Each encoded word is segmented and the segmentation results are input into the hidden layer of the preset spell detection model, and the output of the hidden layer is extracted to obtain multiple representations of each word;

[0036] The multiple representations of each word are aggregated in their respective spaces to obtain the clustering results of the set of correctly spelled words and the set of incorrectly spelled words.

[0037] In one embodiment of the present invention, the step of inputting each of the words in the language to be detected into a preset spelling detection model to detect whether there are spelling errors includes:

[0038] Each word of the language to be detected is input into the encoder of the preset spelling detection model for encoding processing;

[0039] The encoded words of the language to be detected are segmented and the segmentation results are input into the hidden layer of the preset spelling detection model. The output of the hidden layer is extracted to obtain multiple representations of each word of the language to be detected.

[0040] Based on the various representations of each word in the language to be detected, calculate its first average distance to all words in the set of correctly spelled words, and calculate its second average distance to all words in the set of incorrectly spelled words;

[0041] For each word in the language to be detected, if the value of the first average distance exceeds the first preset threshold, it is determined that the word in the language to be detected is a word with a spelling error; if the value of the second average distance exceeds the second preset threshold, it is determined that the word in the language to be detected is a word with a correct spelling.

[0042] In one embodiment of the present invention, the step of inputting a sentence to be detected containing at least one word of the language to be detected into a preset semantic detection model to detect whether there is a semantic error includes:

[0043] The sentence to be detected is segmented into words, and the segmentation results are input into the encoder of the preset semantic detection model for processing to obtain the target matrix;

[0044] Each column of the target matrix is ​​input into the classifier of the preset semantic detection model for processing to obtain the corresponding binary classification probability;

[0045] The binary classification probability is used to determine whether there are semantic errors in the target language words in the sentence to be detected.

[0046] In one embodiment of the present invention, the step of inputting the word to be detected into a preset spelling correction model for spelling correction processing if the word to be detected has a spelling error includes:

[0047] For each word in the language to be detected that contains a spelling error, perform the following steps:

[0048] The edit distance between each word in the target language and each word in the preset dictionary is calculated using the preset spelling correction model.

[0049] If there is a word with the smallest edit distance in the preset dictionary, then the word with the smallest edit distance is used to replace the word in the language to be detected in order to correct the error of the word in the language to be detected;

[0050] If there are multiple words with the smallest edit distance in the preset dictionary, the word with the highest previously returned frequency among the multiple words with the smallest edit distance is used to replace the word in the language to be detected, so as to correct the word in the language to be detected.

[0051] The preset dictionary is a language dictionary corresponding to the target language.

[0052] In one embodiment of the present invention, the step of inputting the statement to be detected into a preset semantic error correction model for semantic error correction processing includes:

[0053] Extract at least one word to be corrected from the statement to be detected that contains semantic errors;

[0054] The preset dictionary is queried, and all candidate words in the preset dictionary whose edit distance to the word to be corrected is less than or equal to a preset threshold are selected as the candidate set.

[0055] The words to be corrected in the sentence to be detected are masked with preset markers, and the masked sentence to be detected is input into a preset semantic error correction model.

[0056] The preset semantic error correction model predicts the probability of replacing the masked word to be corrected with each candidate word in the candidate set, and selects the candidate word with the highest probability value as the correction word.

[0057] In one embodiment of the present invention, returning the text to be detected corresponding to the semantically corrected statement to be detected as the detected text includes:

[0058] Merge the corrected words with the statement to be detected;

[0059] During merging, if the length of the corrected word is inconsistent with the length of the corresponding word to be corrected, or if there are multiple corrected words in a sentence, the word to be corrected in the sentence to be detected will be deleted, and then the corresponding corrected word will be inserted.

[0060] The text to be detected corresponding to the merged statement to be detected will be returned as the detected text.

[0061] In one embodiment of the present invention, before inputting the statement to be detected into a preset semantic error correction model, the method further includes:

[0062] The preset semantic error correction model is trained in the following manner:

[0063] Use a predetermined number of correct target language texts or core language texts containing target language words as the training set;

[0064] The text in the training set is input into the preset semantic error correction model, and the preset semantic error correction model randomly masks some words in the input text.

[0065] For each masked word, the preset semantic error correction model is trained to replace the masked word with the predicted word.

[0066] Secondly, the present invention also provides a multilingual text detection and error correction system, the system comprising:

[0067] The recognition module is used to acquire the text to be detected and to perform multilingual character recognition on the text to be detected to obtain at least one sentence to be recognized. The sentence to be recognized contains characters of a main language and characters of at least one target language. The main language is different from the target language.

[0068] The detection module is used to perform language detection on the characters of the target language in the sentence to be identified, to obtain the words of the language to be detected, and to perform spelling detection and semantic detection on the words of the language to be detected.

[0069] The error correction module is used to perform corresponding spelling and / or semantic correction on words with spelling and / or semantic errors if at least one word in the language to be detected has a spelling error and / or a semantic error.

[0070] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the multilingual text detection and error correction method as described in any of the first aspects.

[0071] Fourthly, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the multilingual text detection and error correction method as described in any of the first aspects.

[0072] This invention provides a multilingual text detection and correction method, system, electronic device, and storage medium. It identifies foreign characters in input text to determine the language of those characters and then uses artificial intelligence to perform spelling and semantic detection on the foreign characters. Based on the presence of spelling and semantic errors, it performs corresponding spelling and semantic correction processing. This invention can better understand the semantics of text in cross-linguistic contexts, detecting all target language characters in the text and correcting only the words with errors. Attached Figure Description

[0073] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other embodiments can be obtained based on these drawings without creative effort.

[0074] Figure 1 This is a flowchart illustrating the multilingual text detection and error correction method provided by the present invention;

[0075] Figure 2 This is a schematic diagram of the language detection process provided in an embodiment of the present invention;

[0076] Figure 3 This is a schematic diagram of the semantic detection process provided in an embodiment of the present invention;

[0077] Figure 4 This is a schematic diagram of the detection module and error correction module provided in an embodiment of the present invention;

[0078] Figure 5 This is a schematic diagram of the multilingual text detection and error correction method provided in an embodiment of the present invention;

[0079] Figure 6 Is with Figure 5 Corresponding flowchart;

[0080] Figure 7 This is a schematic diagram of the structure of the multilingual text detection and error correction system provided by the present invention;

[0081] Figure 8 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation

[0082] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below with reference to the accompanying drawings in the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0083] In the description of the present invention and the claims, as well as in the above drawings, the terms "first", "second", etc. are used to distinguish similar objects and do not necessarily have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments described herein can be implemented in an order different from that shown or described herein.

[0084] The following describes the technical scenarios related to the present invention:

[0085] With the popularization of electronic intelligent devices and the rapid development of informatization, a vast amount of manuscripts are presented in electronic form and are continuously increasing. At the same time, with the development of social languages, code-switching (such as switching from Chinese to English) appears more and more frequently in social networks. People increasingly bring in some foreign languages when speaking to express more appropriately. Proofreading and correcting non-Chinese characters in such Chinese-context manuscripts will consume a huge amount of manpower and time. And there are many cases of foreign characters appearing in the Chinese context. Chinese and foreign languages are often mixed in modern social networks. For example, "Xiaozhang is really a gafe" (Spanish slang: unlucky guy). These situations may all have spelling mistakes and semantic contradiction mistakes.

[0086] To solve the problem of incorrect speech understanding of cross-language texts in the prior art, the present invention provides a multi-language text detection and correction method, system, electronic device and storage medium. By identifying foreign characters in the input text, the language of the foreign characters is determined, and then the spelling and semantics of the foreign characters are detected by means of artificial intelligence. Then, corresponding spelling correction and semantic correction are performed according to spelling mistakes and semantic mistakes. The present invention can better understand the text semantics in a cross-language context, detect all characters in the text in the target languages, and only correct the words detected with errors.

[0087] The following combines Figures 1-8 to describe the multi-language text detection and correction method, system, electronic device and storage medium of the present invention.

[0088] Figure 1 is a schematic flowchart of the multi-language text detection and correction method provided by the present invention. As Figure 1As shown in the figure. A multilingual text detection and correction method provided by an embodiment of the present invention, the method includes:

[0089] Step 101, obtain the text to be detected, and perform multilingual character recognition on the text to be detected to obtain at least one statement to be recognized, where the statement to be recognized includes characters of the main language and characters of at least one target language, and the main language is different from the target language.

[0090] Exemplarily, the characters of the main language refer to Chinese characters, and the characters of the target language refer to foreign characters.

[0091] Exemplarily, the non-Chinese characters include foreign characters and preset symbol characters. Non-Chinese characters include Arabic numerals, Latin letters, punctuation marks, etc. The foreign characters in the present invention refer to characters containing Latin letters, while Arabic numerals and punctuation marks belong to preset symbol characters. <W

[0092] Exemplarily, a text to be detected includes one or more statements to be recognized, and each statement to be recognized can be composed of Chinese characters and non-Chinese characters.

[0093] For example, the statement "Hello, guten Tag" is composed of the Chinese characters "Hello", the foreign characters "guten Tag", and the punctuation mark ",". The foreign characters "guten Tag" are composed of the word "guten" and the word "Tag".

[0094] Step 102, perform language detection on the characters of the target language in the statement to be recognized to obtain the words of the language to be detected, and perform spelling detection and semantic detection on the words of the language to be detected.

[0095] Among them, the words of the language to be detected refer to the words corresponding to a certain language to be detected. For example, the above "guten" and "Tag" are the words of the language to be detected.

[0096] Step 103, if there are spelling errors and / or semantic errors in at least one of the words of the language to be detected, perform corresponding spelling correction and / or semantic correction on the words with spelling errors and / or semantic errors.

[0097] It should be noted that the embodiment of the present invention is directed to non-Chinese characters in the context of Chinese in the text to be detected, that is, the statements to be recognized in the text to be detected are mixed with foreign characters. If there are no foreign characters in the statement to be recognized, the detection and correction of Chinese characters are processed by the existing Chinese text detection and correction system.

[0098] This invention employs different error correction methods for different detection errors of foreign characters. For example, for spelling errors, a spelling correction method is used; for semantic errors, a semantic correction method is used. This improves error correction efficiency.

[0099] The following is a detailed description of steps 101 to 103 above.

[0100] In step 101 above, obtaining the text to be detected and performing multilingual character recognition on the text to be detected to obtain at least one sentence to be recognized includes:

[0101] Step 1011: Perform data cleaning on the text to be detected to remove illegal characters and garbled text caused by encoding errors.

[0102] Step 1012: Segment the text to be detected to obtain at least one sentence to be identified, and delete the whitespace characters at the beginning and end of each sentence to be identified.

[0103] For example, the text to be detected is segmented into sentences using the LTP (Language Technology Platform) tool, and whitespace characters at the beginning and end of sentences are removed so that the input of the subsequent model can be in units of sentences.

[0104] LTP provides a suite of Chinese natural language processing tools that users can use to perform tasks such as word segmentation, part-of-speech tagging, and syntactic analysis on Chinese text.

[0105] Step 1013: Identify the characters of the statement to be identified, and if characters of the target language are present, record the position of the characters of the target language in the statement to be identified.

[0106] For example, the unicodedata (Unicode Database, a module in the Python language) module is used to identify the language classification of different characters in a sentence, and at the same time record their position in the sentence, in units of characters.

[0107] The unicodedata class provides the category function, which takes a single character as input and returns a string with multiple meanings to identify the category of the character, including the part that can be used to distinguish Chinese characters.

[0108] Specifically, each character is fed into the `category` function one by one. If the return value begins with "N", the character is marked as "Num" (number); if it begins with "P", the character is marked as "Punc" (punctuation); if it begins with "L", further judgment is made: if the Unicode encoding value of the character falls within any of the following ranges:

[0109] If the given values ​​are [0x4E00,0x9FFF], [0x3400,0x4DBF], [0x20000,0x2A6DF], [0x2A700,0x2B73F], [0x2B740,0x2B81F], [0x2B820,0x2CEAF], [0xF900,0xFAFF], [0x2F800,0x2FA1F], then the character is marked as the Chinese character "ZH". Otherwise, it is marked as the foreign character "OT". Adjacent and identical character markers are then merged into a range of markers, and the result is returned.

[0110] For example, taking the sentence to be recognized, "I need to modify my presentation PTT tomorrow.", the returned value is "[0,3,“ZH”),[3,15,“OT”),[15,16,“ZH”),[16,19,“OT”),[19,23,“ZH”),[23,24,“Punc”)". The character count starts from 0, and the intervals are closed at the beginning and open at the end. For example, [0,3,“ZH”) indicates that the characters from position 0 to position 2 are Chinese characters, [3,15,“OT”) indicates that the characters from position 3 to position 14 are foreign characters, [23,24,“Punc”) indicates that position 23 is a punctuation mark, and so on.

[0111] For example, if the target language characters (i.e. foreign language characters) are not present, the original text is returned directly or the existing Chinese text detection and correction system is used for processing.

[0112] Figure 2 This is a schematic diagram of the language detection process provided in an embodiment of the present invention, such as... Figure 2 As shown. In step 102 above, the language detection of the target language characters in the statement to be identified includes:

[0113] Step 1021: Input the sentence to be recognized containing characters of the target language into the preset language detection model.

[0114] For example, the preset language detection model adopts a sequence labeling model based on XLM-Roberta.

[0115] Pre-trained models can be categorized by language into monolingual pre-trained models and multilingual pre-trained models. Monolingual pre-trained models are those pre-trained on corpora of only one language and can only handle tasks in that language; multilingual pre-trained models are those pre-trained on corpora of multiple languages ​​and can handle tasks in multiple languages.

[0116] XLM-Roberta is a typical multilingual pre-trained model, a converter-based language model that relies on a masked language model as its target and can handle text in over 100 different languages. The neural network model in this embodiment is developed based on XLM-Roberta, but this embodiment is not limited to a neural network structure based on XLM-Roberta; other neural network structures are also possible.

[0117] For example, the XLM-Roberta configuration in this embodiment of the invention can adopt either the first or second configuration below:

[0118] The first type has 12 layers and 768 dimensions (XLM-Roberta-base);

[0119] The second type has 24 layers and 1024 dimensions (XLM-Roberta-large).

[0120] For example, in an XLM-Roberta-based sequence labeling model, the language detection task can be represented as a multi-class classification task, where the dataset X contains n sentences, X={x1, x2, ..., x...} n The sentence can be represented as x. i ={w1, w2, ..., w m}, where at least one word is a foreign language word, and each foreign language word in a sentence corresponds to a label representing its language, Y={y1, y2, ..., y n} where y = {0, 1, ..., q}, and q is the number of foreign languages.

[0121] Step 1022: The preset language detection model performs word segmentation on the input sentence to be identified based on the sequence labeling mechanism, and outputs the language corresponding to the target language words in the sentence to be identified.

[0122] For example, step 1022 includes:

[0123] Step 10221: Segment the statement to be recognized into words to obtain a word segmentation list with at least one word, and add preset special characters to the beginning and end of the word segmentation list to indicate the start and end.

[0124] For example, suppose the input statement to be recognized is: "I need to revise my presentation PTT tomorrow." First, it is segmented by the XLM-Roberta tokenizer, resulting in ['I', 'tomorrow', 'pres', 'an', 'tation', 'of', 'P', 'TT', 'need', 'revise', '。']. Then, preset special characters are added to the beginning and end of this segmented list. <s>The '\s' and '<\s>' are used to indicate the beginning and end of a sentence.

[0125] Step 10222: Map each word in the word segmentation list to its corresponding identifier to obtain an identifier list.

[0126] For example, mapping each token (segment) in the above word segmentation list to an identifier (ID) yields an identifier list (ID list), which is:

[0127] [0,13129,72938,9518,66,22062,43,683,13739,41604,45123,30,2].

[0128] Step 10223: Input the list of identifiers into the embedding layer of the preset language detection model to convert it into a first matrix with a first preset dimension (e.g., (13, 768)).

[0129] For example, when the above list of IDs is input into an XLM-Roberta model, it first passes through the embedding layer of the XLM-Roberta model. The embedding layer converts the list of IDs into a first matrix with the same length as the list of IDs and a width equal to the XLM-Roberta dimension (768 or 1024 dimensions).

[0130] Step 10224: Input the first matrix into the multi-layer transformer of the preset language detection model for calculation, so as to output a second matrix with a second preset dimension (e.g., (13, 3)). The second matrix represents the semantic information of the word segment corresponding to the identifier in the context.

[0131] A transformer is a transformation model that relies entirely on a self-attention mechanism to compute its input and output representations. The most prominent feature of a transformer is its excellent parallel computing capability.

[0132] For example, the first matrix is ​​fed into the encoder of the XLM-Roberta model. After calculation by multiple transformers, a second matrix is ​​output with the same length as the ID list and the width is the XLM-Roberta dimension (768 or 1024 dimensions).

[0133] Step 10225: Input the second matrix into the fully connected layer of the preset language detection model, and normalize the output of the fully connected layer to obtain the language probability of each word segment corresponding to each identifier.

[0134] For example, a linear transformation is used to convert the second matrix into a prediction matrix, which has the same length and number of tag categories as the ID list. At the position of each ID, a vector of length equal to the number of tag categories is obtained. This vector is input into a fully connected layer and normalized (softmax) to calculate the probability of the number of tag categories, i.e., the probability that the token (segmentation) corresponding to the ID belongs to each category.

[0135] Step 10226: Determine the language corresponding to each word segment based on its language probability.

[0136] The following application example illustrates the language detection process described above.

[0137] For ease of illustration, it is assumed that the target languages ​​(i.e. foreign languages) identified by the preset language detection model are English and German (but the present invention is not limited to these two languages), represented by the numbers 1 and 2, and 0 is used to represent "other" (non-foreign language characters), so there are a total of 3 categories.

[0138] For example, input the statement to be recognized: "I need to modify my presentation PTT tomorrow."

[0139] After segmenting the above example sentence and adding special characters, it becomes:

[0140] [' <s>',' I',' tomorrow','pres','an','tation','of','P','TT','still','revise','。 ','<\s>''。

[0141] After word segmentation, the above example sentence has a length of 13. If we use XLM-Roberta with a dimension of 768, then the second matrix M of the encoder has a dimension of 13*768. The output layer is a linear layer, mapping the second matrix M to a 13*3 matrix. This is achieved by performing softmax normalization on each column of the second matrix M, resulting in a 13*3 matrix where each column represents the category probability corresponding to the token at that position. The position corresponding to the maximum probability in each column results in a vector of length 13: (0,0,0,1,1,1,0,1,1,0,0,0,0).

[0142] Based on the relationship between the category labels and numbers above, this vector can be interpreted as ('o','o','o','en','en','en','o','en','o','o','o','o','o'). Here, 'o' represents a non-foreign language character, and 'en' represents English. Since the example sentence above does not contain German, no corresponding marker is output.

[0143] Once the target language corresponding to the word to be detected is determined, the subsequent detection and correction of the word to be detected can be performed using the corresponding model (or "module") and the preset dictionary corresponding to the target language.

[0144] In step 102 above, the spelling detection and semantic detection of the words in the language to be detected includes: step 1021, inputting each word in the language to be detected into a preset spelling detection model to detect whether there are spelling errors.

[0145] For example, before performing step 1021, the method further includes:

[0146] Step 1020: Input a preset number of language words into the preset pinyin detection model for learning. Specifically, this includes:

[0147] Step 10201: Input a preset number of reference language words into the encoder of the preset spelling detection model for encoding processing. The preset number of reference language words includes a set of correctly spelled words and a set of incorrectly spelled words that have been labeled.

[0148] For example, the preset pinyin detection model uses the XLM-Roberta-base model as the encoder and uses an unsupervised approach to detect word spelling errors.

[0149] The difference between supervised and unsupervised supervision lies in:

[0150] First, supervision involves labels, while unsupervised supervision involves no labels.

[0151] Supervised learning involves first training the model using known training samples (known inputs and corresponding outputs) to obtain an optimal model. This model is then applied to new data, mapping it to the output results. After this process, the model acquires predictive capabilities. Unsupervised learning, in contrast, involves no training process; instead, it directly uses data for modeling and analysis.

[0152] Second, supervised classification is the same as unsupervised clustering.

[0153] The core of supervised learning is classification, while the core of unsupervised learning is clustering (dividing a dataset into multiple classes composed of similar objects). Supervised learning involves selecting a classifier and determining weights, while unsupervised learning involves density estimation (finding statistical values ​​that describe the data). In other words, unsupervised algorithms only need to know how to calculate similarity to begin working.

[0154] Third, supervision is the same dimension, while lack of supervision is a reduction in dimension.

[0155] If the input to a supervised learning dataset is n-dimensional, the features are considered n-dimensional, i.e., y = f(xi) or p(y|xi), i = n. This typically lacks dimensionality reduction capabilities. Unsupervised learning, on the other hand, often involves deep learning for feature extraction or directly employs layered clustering or item clustering to reduce the dimensionality of the data features, making i... <n。

[0156] Fourth, supervised classification involves qualitative analysis during classification, while unsupervised classification involves clustering first and then qualitative analysis.

[0157] Supervised outputs, meaning pre-classified results, are directly labeled. Unsupervised outputs simply result in clusters of groups.

[0158] Step 10202: Segment each encoded word and input the segmentation results into the hidden layer of the preset spell detection model, and extract the output of the hidden layer to obtain multiple representations of each word.

[0159] For example, before the preset spell detection model performs spell detection on words, a preset number of reference language words, including a set of correctly spelled words {Ci} and a set of incorrectly spelled words {Wi}, are first encoded using the same encoder. The output of the 12 hidden layers in the model is then extracted, resulting in 12 representations for each word. Because each layer of the model captures different features of the word, generally speaking, lower and middle layers can capture grammatical phrase features well, while higher layers extract richer semantic features. Therefore, the clustering effect at each layer has different significance for word error detection.

[0160] It should be noted that the above-mentioned sets of correctly spelled words {Ci} and incorrectly spelled words {Wi} were collected in advance. The set of correctly spelled words {Ci} can come from standard dictionaries of various languages; the set of incorrectly spelled words {Wi} can come from commonly misspelled words collected manually.

[0161] For example, for each of the 12 representations of the correctly spelled words set {Ci} and the incorrectly spelled words set {Wi}, all tokens are averaged.

[0162] Suppose that a word w is segmented into n tokens {t1, t2, ..., tn}. n }, then calculate {t1,t2,…,t} n The 12-level representation of} yields a total of n*12 vectors:

[0163] {v 1,1 ,...,v 1,12 ,v 2,1 ,...,v 2,12 ,…,v n,1 ,...,v n,12 };

[0164] Among them, v i,j The meaning is token t i The representation at layer j. The average pooling operation is to average over all tokens at each layer: r j =(v 1,j +v 2,j +…v n,j ). r j This is the average pooled representation of the word at layer j, with a dimension of 768.

[0165] Step 1023: Aggregate the multiple representations of each word in their respective spaces to obtain the clustering results of the set of correctly spelled words and the set of incorrectly spelled words.

[0166] For example, the TSNE algorithm (a dimensionality reduction algorithm) is used to apply the above r j Dimensionality reduction is performed by embedding the average pooling representations of all words into the same low-dimensional space. The set of correctly spelled words {Ci} and the set of incorrectly spelled words {Wi} will be aggregated into different clusters in the planar space. Since the features captured by each layer of the model are different, the aggregation effect of the above 12 representations in their respective spaces will also differ in detail. However, the set of incorrectly spelled words {Ci} and the set of incorrectly spelled words {Wi} will be clearly separated and clustered in their respective clusters.

[0167] For example, given the set of correctly spelled words {Ci} and the set of incorrectly spelled words {Wi}, we obtain 12 representations for each word in these sets. We then use the TSNE algorithm to embed these representations into 12 low-dimensional spaces (e.g., less than 10 dimensions, typically 2, 3, or 4). In each space, the set of correctly spelled words {Ci} and the set of incorrectly spelled words {Wi} are clustered into two groups.

[0168] Using the projection space obtained from the set of correctly spelled words {Ci} and the set of incorrectly spelled words {Wi} as a reference, subsequent detection of words in the language to be detected can be performed.

[0169] Step 1021 above, which involves inputting each of the words in the language to be detected into a preset spelling detection model to detect whether there are spelling errors, includes:

[0170] Step 10211: Input each of the words in the language to be detected into the encoder of the preset spelling detection model for encoding processing.

[0171] For example, when detecting a word in a language to be detected, the same encoder as described above is used to encode it, that is, an encoder based on the XLM-Roberta model is used.

[0172] Step 10212: Segment the encoded words of the language to be detected and input the segmentation results into the hidden layer of the preset spelling detection model, and extract the output of the hidden layer to obtain multiple representations of each word of the language to be detected.

[0173] For example, after calculation, the output is the average of the representations of each of the 12 transformer layers, i.e., the average pooling described above.

[0174] For example, if the word to be detected is "presantation", after word segmentation it is ['pres', 'an', 'tation'], with a length of 3. Each of the 12 transformer layers will calculate a matrix of size 3*768. Then, the average value is calculated on the first dimension to obtain 12 vectors of length 768, which are the 12 representations of the word to be detected.

[0175] Step 10213: Based on the multiple representations of each word in the language to be detected, calculate its first average distance to all words in the set of correctly spelled words, and calculate its second average distance to all words in the set of incorrectly spelled words.

[0176] For example, using the TSNE algorithm, under the same parameter control, each word of the language to be detected is embedded into the aforementioned 12 spaces. The first average distance between it and all words in the correct spelling cluster is calculated, and the second average distance between it and all words in the incorrect spelling cluster is calculated. A total of 12 pairs of distances are obtained.

[0177] Step 10214: For each word in the language to be detected, if the value of the first average distance exceeds the first preset threshold, it is determined that the word in the language to be detected is a word with a spelling error; if the value of the second average distance exceeds the second preset threshold, it is determined that the word in the language to be detected is a word with a correct spelling.

[0178] For example, assuming 12 representations of the word "presantation" are obtained, calculate its first average distance to all words in the correct spelling cluster, and calculate its second average distance to all words in the incorrect spelling cluster. If the number of words closer to the incorrect spelling cluster for the word "presantation" is greater (e.g., exceeding the second preset threshold), then the word "presantation" is determined to be an incorrectly spelled word, and the subsequent spelling correction step is initiated.

[0179] Step 1022: If the preset spelling detection model detects that there are no spelling errors in each of the words in the language to be detected, then the sentence to be detected containing at least one word in the language to be detected is input into the preset semantic detection model to detect whether there are semantic errors.

[0180] For example, the preset semantic detection model uses the XLM-Roberta model as the subject. The semantic detection task in the preset semantic detection model can be represented as a binary classification task, where the dataset X contains n sentences, X={x1, x2, ..., x...} n Each sentence corresponds to a semantic tag indicating whether its semantics are erroneous.

[0181] Step 1022 above specifically includes:

[0182] Step 10221: The sentence to be detected is segmented into words, and the segmentation results are input into the encoder of the preset semantic detection model for processing to obtain the target matrix.

[0183] For example, the input of the preset semantic detection model is the statement to be detected, and its output is a binary classification prediction probability, indicating whether the statement to be detected has a semantic error.

[0184] Step 10222: Input each column of the target matrix into the classifier of the preset semantic detection model for processing to obtain the corresponding binary classification probability.

[0185] For example, the input to the preset semantic detection model is the first column of the target matrix output by the encoder, and its output is the classification probability.

[0186] For example, the encoder outputs a target matrix M with dimensions of (13,768) or (13,1024). The output layer takes the first column M[0,:] of the target matrix M as input and feeds it into a linear binary classifier to output a probability. The larger the probability value, the more likely it is to contain semantic errors.

[0187] For the example sentence "I still need to revise my PTT presentation tomorrow," the preset semantic detection model outputs a prediction close to 1, indicating that the sentence to be detected contains a semantically incorrect word, namely "PTT." Although PTT is a correct abbreviation, the preset semantic detection model will consider it a semantic error and will consider PPT to be more appropriate.

[0188] Step 10223: Determine whether there are semantic errors in the words of the language to be detected in the sentence to be detected based on the binary classification probability.

[0189] Step 1023: If the statement to be detected does not have a semantic error, then the text to be detected corresponding to the statement to be detected is returned as the detected text.

[0190] The semantic detection described above is illustrated below with an application example.

[0191] Figure 3 This is a schematic diagram of the semantic detection process provided in an embodiment of the present invention, such as... Figure 3 As shown.

[0192] Step 301: Input the sentence to be detected that has no spelling errors or has been spelled correctly into the preset semantic detection model.

[0193] For example, input "I like watching MBA games" into the preset semantic detection model.

[0194] Step 302: The sentence to be detected is segmented into words and passed through the embedding layer of the preset semantic detection model and the last layer of the multi-layer transformer for output.

[0195] Step 303: Extract the representation of the special marker [CLS] in the last layer output of the multi-layer transformer and classify it.

[0196] Step 304: Determine whether the statement to be detected has semantic errors by using a normalization function (softmax).

[0197] If the statement to be detected contains a semantic error, it will proceed to the subsequent preset semantic error correction module to correct the error; otherwise, the text corresponding to the statement to be detected will be returned. Figure 3 Although the spelling of MBA is correct, it is judged as a semantic error in the preset semantic detection model, which would consider NBA to be more appropriate.

[0198] Figure 4 This is a schematic diagram of the detection module and error correction module provided in an embodiment of the present invention, as shown below. Figure 4 As shown. In step 103 above, if at least one of the words in the language to be detected has a spelling error and / or a semantic error, then performing corresponding spelling correction and / or semantic correction on the words with spelling errors and / or semantic errors includes:

[0199] Step 1031: If the word in the language to be detected has a spelling error, then the word in the language to be detected is input into a preset spelling correction model for spelling correction processing.

[0200] For example, for spelling errors in words in the target language (i.e., foreign language words), a preset dictionary (i.e., a language dictionary corresponding to the target language) is used for error correction. The preset dictionary labels the frequency of each foreign language word. Based on the edit distance dynamic programming algorithm, the candidate word with the smallest edit distance is obtained. If there are multiple candidate words, the word with the highest frequency is returned from among them. Edit distance refers to the minimum number of editing operations required to transform one string into another. The editing operations used in this embodiment include one or more combinations of replacing one character with another, inserting a character, and deleting a character.

[0201] For example, step 1031 includes:

[0202] For each word in the language to be detected that contains a spelling error, perform the following steps:

[0203] Step 10311: Calculate the edit distance between each word in the target language and each word in the preset dictionary using the preset spelling correction model. The preset dictionary is the language dictionary corresponding to the target language.

[0204] For example, the preset spelling correction model can be a non-neural network model, whose input is a word in the language to be detected (i.e., a foreign language word), and whose output is the corrected word. If the input foreign language word does not contain any errors, the foreign language word itself is returned.

[0205] For example, taking the word "presantation" in the above-mentioned sentence as an example, the preset spelling correction model first calculates the edit distance between "presantation" and each word in the preset dictionary, and selects the word with the smallest edit distance between the preset dictionary and "presantation".

[0206] Step 10312: If there is a word with the smallest edit distance in the preset dictionary, then replace the word in the language to be detected with the word with the smallest edit distance to correct the word in the language to be detected.

[0207] Step 10313: If there are multiple words with the smallest edit distance in the preset dictionary, then replace the word in the language to be detected with the word with the highest previously returned frequency among the multiple words with the smallest edit distance, so as to correct the word in the language to be detected.

[0208] For example, in the above example sentence, if multiple words have the same edit distance, the word with the highest frequency is returned. The word with the smallest edit distance to "presantation" is "presentation", with an edit distance of 1 ("a" → "e"). There is only this one word, so "presentation" is returned.

[0209] Step 1032: Input the sentence to be detected, which contains the words of the language to be detected after spelling correction, into the preset semantic detection model to detect whether there are semantic errors.

[0210] Step 1033: If the statement to be detected does not have semantic errors, then the text to be detected corresponding to the spell-corrected statement to be detected is returned as the detected text.

[0211] Step 1034: If the statement to be detected has a semantic error, the statement to be detected is input into a preset semantic error correction model for semantic error correction processing, and the text to be detected corresponding to the semantically corrected statement to be detected is returned as the detected text.

[0212] For example, before performing step 1034, the method further includes constructing a pre-trained model and pre-training the pre-trained model.

[0213] The pre-trained model refers to a model that has been pre-trained on a large-scale corpus (generally exceeding 10G in size) using the Masked Language Modeling (MLM) task.

[0214] For example, the pre-trained model is an XLM-Roberta model.

[0215] For example, the pre-trained model is pre-trained in the following manner:

[0216] The text is taken as input, and some words in the text are masked. The pre-trained model then restores the masked words.

[0217] For example, if a sentence in the input text is "training process of the pre-trained model", the pre-trained model will first randomly mask it with [MASK], resulting in "pre-training [MASK][MASK] training [MASK] process". Using this sentence as training data, the pre-trained model is required to restore the masked characters at [MASK], i.e., "model, type, process".

[0218] It should be noted that after the XLM-Roberta model is pre-trained, it will be trained again in the specific downstream task.

[0219] For example, the pre-trained model consists of an embedding layer, an encoder layer, and an output layer. The embedding layer maps the input text, converting it into a series of vectors, called the vector representation of the text. The encoder layer, composed of multiple stacked transformers (typically 12 or 24), performs a series of non-linear transformations on the vector representation. The output layer uses the output of the encoder (i.e., the output of the last transformer) to make predictions for a specific task. The design of the output layer can differ for different tasks. For example, in the aforementioned preset language detection model, the output of the last transformer layer is taken and fed into a fully connected layer and softmax to classify and determine the language of the token.

[0220] For example, before performing step 1034, the method further includes:

[0221] Train the preset semantic error correction model.

[0222] For example, the preset semantic error correction model is trained in the following manner:

[0223] A predetermined number of correct target language texts or core language texts containing target language words are used as a training set. The texts in the training set are input into the predetermined semantic error correction model. The predetermined semantic error correction model randomly masks some words in the input text, and the randomly masked words are designated as [MASK]. For each masked word, the predetermined semantic error correction model is trained to replace the masked word with a predicted word, that is, the model is trained to restore the [MASK] word.

[0224] It should be noted that the aforementioned pre-defined semantic error correction model is based on the XLM-Roberta model. The [MASK] it trains masks and requires the restoration of complete words, rather than finer-grained tokens (word segmentation). Therefore, it differs from the MLM model described above. For example:

[0225] Suppose the input text contains the sentence "The green-crowned brilliant is a large hummingbird". Then, replace the entire "hummingbird" with "[MASK]": "The green-crowned brilliant is a large [MASK]", and train the preset semantic error correction model to predict "[MASK]" as "hummingbird".

[0226] In the MLM task of the pre-trained model, "hummingbird" is split into two tokens ("humming" and "bird"), but the word "hummingbird" does not exist, making it impossible to perform the reconstruction prediction task. To achieve the reconstruction prediction task, this invention expands the output prediction vocabulary of the pre-trained model by adding all commonly used words, such as "hummingbird," so that the pre-trained model can directly reconstruct "hummingbird" from [MASK].

[0227] Therefore, the difference between the preset semantic error correction model and the pre-trained model (MLM) is that, in the MASK restoration stage, the output vocabulary of the pre-trained model (MLM) is the same as the input vocabulary, while the output vocabulary of the semantic error correction model is different from the input vocabulary and is larger, thus enabling it to restore complete words.

[0228] Specifically, for the input "The green-crowned brilliant is a large[MASK]", after the encoder calculates matrix M, the preset semantic error correction model calculates the dot product of the vector at the [MASK] position and the vector (v1, v2, ... vn) of each word in the vocabulary. The word corresponding to the largest product ("hummingbird") is used as the prediction. The vocabulary size is usually set to the order of hundreds of thousands to cover as many words as possible.

[0229] For example, step 1034 above includes:

[0230] Step 10341: Extract at least one word to be corrected from the statement to be detected that has semantic errors.

[0231] For example, if a certain sentence in the input text to be detected is "zhurou_huoxing_rover successfully landed on Mars", the "zhurou" is detected as a valid pinyin by the above-mentioned pre-set spelling detection model, meaning there is no spelling error. However, the above-mentioned pre-set semantic detection model detects that its semantics are incorrect.

[0232] Step 10342: Query the preset dictionary and select all candidate words in the preset dictionary whose edit distance to the word to be corrected is less than or equal to a preset threshold as the candidate set.

[0233] For example, in the above example, the legal pinyin with an edit distance less than or equal to a preset threshold (e.g., the preset threshold is set to 3) include zhurong (with an edit distance of 2), chirou (with an edit distance of 2), and wenrou (with an edit distance of 3).

[0234] Step 10343: The preset semantic error correction model predicts the probability of replacing the masked word to be corrected with each candidate word in the candidate set, and selects the candidate word with the highest probability value as the correction word.

[0235] For example, replace the input text with "[MASK] Mars rover successfully landed on Mars".

[0236] Step 10344: The preset semantic error correction model predicts the probability of replacing the masked word to be corrected with each candidate word in the candidate set, and the candidate word with the highest probability value is taken as the correction word.

[0237] For example, the preset semantic error correction model predicts that the word with the highest probability of [MASK] is "zhurong", so "zhurong" is returned as the correction word.

[0238] The following application example illustrates the error correction process of the preset semantic error correction model.

[0239] For example, let's take the sentence "I need to revise my presentation PTT tomorrow" as an example. The pre-defined semantic detection model has detected a semantic error, therefore extracting the potentially misspelled words "presentation" and "PTT" from the sentence. It's important to note that "presentation" has already been corrected by the pre-defined spelling correction model.

[0240] Then, a preset threshold is set (e.g., the threshold is 1), and a preset dictionary is queried to find all candidate words whose edit distance to the word to be corrected is less than or equal to the preset threshold as the candidate set. The candidate set for presentation only contains itself, so the presentation does not need to be modified. The candidate set for PTT includes (PTT, PPT, pot), etc.

[0241] The code masks PTT with the word "[MASK]", resulting in the sentence "I need to revise the [MASK] for my presentation tomorrow." This is then fed into the pre-defined semantic error correction model, which restores the characters at the two [MASK] positions. For each [MASK], the top three (top-3) predictions are selected and sorted by probability from highest to lowest to obtain "Title, PPT, Paper". Since PPT appears in the candidate set (PTT, PPT, pot) and has the highest probability, the prediction result PPT is returned.

[0242] In step 1034 above, returning the text to be detected corresponding to the semantically corrected statement to be detected as the detected text includes:

[0243] Step 10345: Merge the corrected word with the statement to be detected.

[0244] For example, during merging, if the length of the corrected word is inconsistent with the length of the corresponding word to be corrected, or if there are multiple corrected words in a sentence, the word to be corrected in the sentence to be detected is deleted, and then the corresponding corrected word is inserted.

[0245] Step 10346: Return the text to be detected corresponding to the merged statement to be detected as the detected text.

[0246] For example, taking the above sentence as an example, "I still need to revise my presentation PTT tomorrow.", the corrected text is "I still need to revise my presentation PPT tomorrow.", and the returned correction position is ([3,15),[17,20)) (counting from 0, the interval is left-closed and right-open), which correspond to "presantation" and "PTT" in the text to be corrected "I still need to revise my presentation PTT tomorrow." respectively.

[0247] In summary, the multilingual text detection and correction method provided by this invention identifies foreign characters in the input text to determine the language of those characters. It then combines artificial intelligence to perform spelling and semantic detection on the foreign characters, and performs corresponding spelling and semantic correction based on any spelling or semantic errors. This method covers cross-language scenarios, better understands the semantics of text in cross-language contexts, detects all target language characters in the text, and corrects only the words with detected errors.

[0248] The following is passed Figure 5 and Figure 6 The multilingual text detection and error correction method provided in the embodiments of the present invention will be described below. Figure 6 More detailed steps can be found above, and will not be repeated below.

[0249] Figure 5 This is a schematic diagram of the multilingual text detection and error correction method provided in an embodiment of the present invention. Figure 6 Is with Figure 5 The corresponding flowchart, such as Figure 5 , Figure 6 As shown.

[0250] Step 601: Obtain the input text to be detected.

[0251] Step 602: The preprocessing module preprocesses the text to be detected.

[0252] For example, the preprocessing includes data cleaning to remove illegal characters and garbled text caused by encoding errors from the text to be detected, and using the LTP tool to segment the text to be processed into sentences to obtain the sentences to be recognized.

[0253] Step 603: The preprocessing module performs foreign language character recognition on the statement to be recognized.

[0254] For example, the unicodedata module is used to identify foreign characters in each statement to be recognized; if a foreign character exists, its position in the statement is recorded. If no foreign character exists, the process returns to its original state and ends.

[0255] Step 604: The preset language detection model determines the language of each foreign word in the sentence to be identified.

[0256] For example, the sequence labeling mechanism in the XLM-Roberta model is used to determine the language of each foreign word in the sentence to be identified.

[0257] Step 605: Input the foreign words into the preset spell detection model.

[0258] Step 606: The preset spelling detection model detects whether there are spelling errors in the foreign word.

[0259] For example, the XLM-Roberta model is used to detect the presence of spelling errors in foreign words in an unsupervised manner. If a spelling error is found, step 607 is executed; if no spelling error is found, step 608 is executed.

[0260] Step 607: The preset spelling correction model calculates the minimum edit distance using the foreign language dictionary corresponding to the foreign language word and corrects the foreign language word.

[0261] Step 608: Input the text to be detected into the preset semantic detection model.

[0262] Step 609: A preset semantic detection model is used to detect whether there are semantic errors in each foreign word in the text to be detected.

[0263] For example, the XLM-Roberta model is used to detect whether there are semantic errors in each foreign word in the text to be detected. If a semantic error exists, proceed to step 611; if no semantic error exists, proceed to step 610.

[0264] Step 610: The preset semantic detection model returns the text after spell correction or returns the original text.

[0265] Step 611: Preset a semantic error correction model to correct foreign words with semantic errors.

[0266] For example, the XLM-Roberta model is used to correct foreign words with semantic errors.

[0267] Step 612: The preset semantic error correction model returns the corrected text.

[0268] The multilingual text detection and correction system provided by the present invention is described below. The multilingual text detection and correction system described below can be referred to in correspondence with the multilingual text detection and correction method described above.

[0269] Figure 7 This is a schematic diagram of the structure of the multilingual text detection and error correction system provided by the present invention, as shown below. Figure 7 As shown. The present invention provides a multilingual text detection and error correction system 700, which includes a recognition module 710, a detection module 720 and an error correction module 730.

[0270] The recognition module 710 is used to acquire the text to be detected and to perform multilingual character recognition on the text to be detected to obtain at least one sentence to be recognized. The sentence to be recognized contains characters of a main language and characters of at least one target language. The main language is different from the target language.

[0271] The detection module 720 is used to perform language detection on the characters of the target language in the sentence to be identified, obtain the words of the language to be detected, and perform spelling detection and semantic detection on the words of the language to be detected.

[0272] The error correction module 730 is used to perform corresponding spelling correction and / or semantic correction on words with spelling errors and / or semantic errors if at least one word in the language to be detected has a spelling error and / or a semantic error.

[0273] For example, the identification module 710 is further configured to:

[0274] The text to be detected is cleaned to remove illegal characters and garbled text caused by encoding errors.

[0275] The text to be detected is segmented into sentences to obtain at least one sentence to be identified, and the whitespace characters at the beginning and end of each sentence to be identified are deleted;

[0276] The characters in the statement to be recognized are identified, and if characters of the target language are present, the position of the characters of the target language in the statement to be recognized is recorded.

[0277] For example, the detection module 720 is further configured to:

[0278] Input the sentence to be recognized containing characters of the target language into the preset language detection model;

[0279] The preset language detection model segments the input sentence to be identified based on a sequence labeling mechanism and outputs the language corresponding to the target language words present in the sentence to be identified.

[0280] For example, the detection module 720 is further configured to:

[0281] The sentence to be identified is segmented into words to obtain a word segmentation list with at least one word, and preset special characters are added to the beginning and end of the word segmentation list to indicate the start and end;

[0282] Map each word in the word segmentation list to its corresponding identifier to obtain an identifier list;

[0283] The list of identifiers is input into the embedding layer of the preset language detection model to convert it into a first matrix with a first preset dimension;

[0284] The first matrix is ​​input into the multi-layer transformer of the preset language detection model for calculation, so as to output a second matrix with a second preset dimension;

[0285] The second matrix is ​​input into the fully connected layer of the preset language detection model, and the output of the fully connected layer is normalized to obtain the language probability of each word segment corresponding to each identifier.

[0286] The language of each word segment is determined based on its language probability.

[0287] For example, the detection module 720 is further configured to:

[0288] Each word in the language to be detected is input into a preset spelling detection model to detect whether there are spelling errors;

[0289] If the preset spelling detection model detects that there are no spelling errors in each of the words in the language to be detected, then the sentence to be detected containing at least one word in the language to be detected is input into the preset semantic detection model to detect whether there are semantic errors.

[0290] If the statement to be detected does not have semantic errors, then the text to be detected corresponding to the statement to be detected will be returned as the detected text.

[0291] For example, the error correction module 730 is further configured to:

[0292] If the word in the language to be detected has a spelling error, the word in the language to be detected is input into a preset spelling correction model for spelling correction processing.

[0293] The sentence to be detected, which contains words of the language to be detected that have undergone spell correction, is input into the preset semantic detection model to detect whether there are semantic errors.

[0294] If the statement to be detected does not have semantic errors, then the text to be detected corresponding to the spell-corrected statement to be detected will be returned as the detected text.

[0295] For example, the error correction module 730 is further configured to:

[0296] If the statement to be detected contains a semantic error, the statement to be detected is input into a preset semantic error correction model for semantic error correction processing.

[0297] The text to be detected corresponding to the semantically corrected statement to be detected is returned as the detected text.

[0298] For example, the system further includes a clustering reference module, which is used to:

[0299] A preset number of reference language words are input into the encoder of the preset spelling detection model for encoding processing. The preset number of reference language words includes a set of correctly spelled words and a set of incorrectly spelled words that have been labeled.

[0300] Each encoded word is segmented and the segmentation results are input into the hidden layer of the preset spell detection model, and the output of the hidden layer is extracted to obtain multiple representations of each word;

[0301] The multiple representations of each word are aggregated in their respective spaces to obtain the clustering results of the set of correctly spelled words and the set of incorrectly spelled words.

[0302] For example, the detection module 720 is further configured to:

[0303] Each word of the language to be detected is input into the encoder of the preset spelling detection model for encoding processing;

[0304] The encoded words of the language to be detected are segmented and the segmentation results are input into the hidden layer of the preset spelling detection model. The output of the hidden layer is extracted to obtain multiple representations of each word of the language to be detected.

[0305] Based on the various representations of each word in the language to be detected, calculate its first average distance to all words in the set of correctly spelled words, and calculate its second average distance to all words in the set of incorrectly spelled words;

[0306] For each word in the language to be detected, if the value of the first average distance exceeds the first preset threshold, it is determined that the word in the language to be detected is a word with a spelling error; if the value of the second average distance exceeds the second preset threshold, it is determined that the word in the language to be detected is a word with a correct spelling.

[0307] For example, the detection module 720 is further configured to:

[0308] The sentence to be detected is segmented into words, and the segmentation results are input into the encoder of the preset semantic detection model for processing to obtain the target matrix;

[0309] Each column of the target matrix is ​​input into the classifier of the preset semantic detection model for processing to obtain the corresponding binary classification probability;

[0310] The binary classification probability is used to determine whether there are semantic errors in the target language words in the sentence to be detected.

[0311] For example, the error correction module 730 is further configured to:

[0312] For each word in the language to be detected that contains a spelling error, perform the following steps:

[0313] The edit distance between each word in the target language and each word in the preset dictionary is calculated using the preset spelling correction model.

[0314] If there is a word with the smallest edit distance in the preset dictionary, then the word with the smallest edit distance is used to replace the word in the language to be detected in order to correct the error of the word in the language to be detected;

[0315] If there are multiple words with the smallest edit distance in the preset dictionary, the word with the highest previously returned frequency among the multiple words with the smallest edit distance is used to replace the word in the language to be detected, so as to correct the word in the language to be detected.

[0316] The preset dictionary is a language dictionary corresponding to the target language.

[0317] For example, the error correction module 730 is further configured to:

[0318] Extract at least one word to be corrected from the statement to be detected that contains semantic errors;

[0319] The preset dictionary is queried, and all candidate words in the preset dictionary whose edit distance to the word to be corrected is less than or equal to a preset threshold are selected as the candidate set.

[0320] The words to be corrected in the sentence to be detected are masked with preset markers, and the masked sentence to be detected is input into a preset semantic error correction model.

[0321] The preset semantic error correction model predicts the probability of replacing the masked word to be corrected with each candidate word in the candidate set, and selects the candidate word with the highest probability value as the correction word.

[0322] For example, the error correction module 730 is further configured to:

[0323] Merge the corrected words with the statement to be detected;

[0324] During merging, if the length of the corrected word is inconsistent with the length of the corresponding word to be corrected, or if there are multiple corrected words in a sentence, the word to be corrected in the sentence to be detected will be deleted, and then the corresponding corrected word will be inserted.

[0325] The text to be detected corresponding to the merged statement to be detected will be returned as the detected text.

[0326] Exemplarily, the system further includes a training module, the training module being used for:

[0327] The preset semantic error correction model is trained in the following manner:

[0328] Use a predetermined number of correct target language texts or core language texts containing target language words as the training set;

[0329] The text in the training set is input into the preset semantic error correction model, and the preset semantic error correction model randomly masks some words in the input text.

[0330] For each masked word, the preset semantic error correction model is trained to replace the masked word with the predicted word.

[0331] Figure 8 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 8 As shown, the electronic device may include: a processor 810, a communications interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communications interface 820, and the memory 830 communicate with each other via the communication bus 840. The processor 810 can call logical instructions in the memory 830 to execute the multilingual text detection and error correction method, the method including:

[0332] The text to be detected is obtained, and multilingual character recognition is performed on the text to be detected to obtain at least one sentence to be recognized. The sentence to be recognized contains characters of a main language and characters of at least one target language. The main language is different from the target language.

[0333] The target language characters in the sentence to be identified are detected to obtain words in the target language, and the words in the target language are then subjected to spelling and semantic detection.

[0334] If at least one word in the language to be detected contains a spelling error and / or a semantic error, then the words containing spelling errors and / or semantic errors shall be subject to corresponding spelling correction and / or semantic correction.

[0335] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0336] On the other hand, the present invention also provides a computer program product, the computer program product including a computer program stored on a non-transitory computer-readable storage medium, the computer program including program instructions, and when the program instructions are executed by a computer, the computer is able to execute the multilingual text detection and error correction methods provided by the above methods.

[0337] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the multilingual text detection and error correction methods provided above.

[0338] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0339] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0340] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.< / s> < / s>

Claims

1. A method for multilingual text detection and correction, the method comprising: The method comprises: acquiring a text to be detected, and performing multilingual character recognition on the text to be detected to obtain at least one to-be-recognized sentence, the to-be-recognized sentence containing characters of a main language and characters of at least one target language, the main language being different from the target language; performing language detection on the characters of the target language in the to-be-recognized sentence to obtain to-be-detected language words, and performing spelling detection and semantic detection on the to-be-detected language words; if at least one of the to-be-detected language words has a spelling error and / or a semantic error, performing corresponding spelling correction and / or semantic correction on the word with the spelling error and / or the semantic error; wherein the language detection on the characters of the target language in the to-be-recognized sentence comprises: inputting the to-be-recognized sentence containing the characters of the target language into a preset language detection model; the preset language detection model performs word segmentation on the input to-be-recognized sentence based on a sequence labeling mechanism, and outputs the language corresponding to the words of the target language existing in the to-be-recognized sentence; wherein the language detection on the characters of the target language in the to-be-recognized sentence comprises: performing word segmentation on the to-be-recognized sentence to obtain a word segmentation list containing at least one word segment, and adding preset special characters at the beginning and the end of the word segmentation list to represent the beginning and the end; mapping each word segment in the word segmentation list to a corresponding identification number to obtain an identification number list; inputting the identification number list into an embedding layer of the preset language detection model to convert it into a first matrix with a first preset dimension; inputting the first matrix into a multi-layer transformer of the preset language detection model for calculation to output a second matrix with a second preset dimension; inputting the second matrix into a fully connected layer of the preset language detection model, and performing normalization calculation on the output of the fully connected layer to obtain the language probability of each word segment corresponding to the identification number; determining the language corresponding to each word segment according to the language probability of each word segment.

2. The multi-lingual text detection and correction method of claim 1, wherein, The acquisition of the text to be detected and the multilingual character recognition on the text to be detected to obtain at least one to-be-recognized sentence comprises: performing data cleaning on the text to be detected to delete illegal characters and garbled characters caused by coding errors in the text to be detected; performing sentence segmentation on the text to be detected to obtain the at least one to-be-recognized sentence, and deleting the blank characters at the beginning and the end of each to-be-recognized sentence; recognizing the characters of the to-be-recognized sentence, and recording the positions of the characters of the target language in the to-be-recognized sentence in the case that there are characters of the target language.

3. The multi-lingual text detection and correction method of claim 1, wherein, The spelling detection and semantic detection on the to-be-detected language words comprise: inputting each to-be-detected language word into a preset spelling detection model to detect whether there is a spelling error; if the preset spelling detection model detects that each word in the to-be-detected language does not have a spelling error, inputting a to-be-detected sentence including at least one word in the to-be-detected language into a preset semantic detection model to detect whether there is a semantic error; if the to-be-detected sentence does not have a semantic error, returning to-be-detected text corresponding to the to-be-detected sentence as detected text.

4. The multi-lingual text detection and correction method of claim 3, wherein, if at least one word in the to-be-detected language has a spelling error and / or a semantic error, performing corresponding spelling correction and / or semantic correction on the word having the spelling error and / or the semantic error, including: if the word in the to-be-detected language has a spelling error, inputting the word in the to-be-detected language into a preset spelling correction model to perform spelling correction processing; inputting a to-be-detected sentence including the word in the to-be-detected language after spelling correction processing into the preset semantic detection model to detect whether there is a semantic error; if the to-be-detected sentence does not have a semantic error, returning the to-be-detected sentence after spelling correction as to-be-detected text as detected text.

5. The multi-lingual text detection and correction method of claim 4, wherein, if at least one word in the to-be-detected language has a spelling error and / or a semantic error, performing corresponding spelling correction and / or semantic correction on the word having the spelling error and / or the semantic error, including: if the to-be-detected sentence has a semantic error, inputting the to-be-detected sentence into a preset semantic correction model to perform semantic correction processing; returning to-be-detected text corresponding to the to-be-detected sentence after semantic correction as detected text.

6. The multi-lingual text detection and correction method of claim 3, wherein, Before the inputting each word in the to-be-detected language into a preset spelling detection model to detect whether there is a spelling error, the method further includes: inputting a preset number of reference language words into an encoder of the preset spelling detection model for encoding processing, the preset number of reference language words including a set of correctly spelled words and a set of incorrectly spelled words that have been labeled; performing word segmentation on each word after encoding and inputting a word segmentation result into a hidden layer of the preset spelling detection model, and extracting an output of the hidden layer to obtain multiple representations of each word; performing aggregation processing on the multiple representations of each word in a respective space to obtain clustering results of the set of correctly spelled words and the set of incorrectly spelled words.

7. The multi-lingual text detection and correction method of claim 6, wherein, The inputting each word in the to-be-detected language into a preset spelling detection model to detect whether there is a spelling error includes: inputting each word in the to-be-detected language into an encoder of the preset spelling detection model for encoding processing; performing word segmentation on the to-be-detected language word after encoding and inputting a word segmentation result into a hidden layer of the preset spelling detection model, and extracting an output of the hidden layer to obtain multiple representations of each to-be-detected language word; according to the multiple representations of each to-be-detected language word, calculating a first average distance thereof from all words in the set of correctly spelled words, and calculating a second average distance thereof from all words in the set of incorrectly spelled words; For each to-be-detected language word, if the value of the first average distance exceeds a first preset threshold, it is determined that the to-be-detected language word is a word with a spelling error, and if the value of the second average distance exceeds a second preset threshold, it is determined that the to-be-detected language word is a word with correct spelling.

8. The multi-lingual text detection and correction method of claim 3, wherein, The inputting of the to-be-detected sentence containing at least one to-be-detected language word into a preset semantic detection model to detect whether there is a semantic error comprises: segmenting the to-be-detected sentence and inputting the segmentation result into an encoder of the preset semantic detection model for processing to obtain a target matrix; inputting each column of the target matrix into a classifier of the preset semantic detection model for processing to obtain a corresponding binary classification probability; determining, according to the binary classification probability, whether a word of a target language in the to-be-detected sentence has a semantic error.

9. The multi-lingual text detection and correction method of claim 4, wherein, The inputting of the to-be-detected language word with a spelling error into a preset spelling correction model for spelling correction processing comprises: For each to-be-detected language word with a spelling error, the following operations are performed: calculating, by the preset spelling correction model, an edit distance between each to-be-detected language word and each word in a preset dictionary; if there is a word with the minimum edit distance in the preset dictionary, replacing the to-be-detected language word with the word with the minimum edit distance to correct the to-be-detected language word; if there are multiple words with the minimum edit distance in the preset dictionary, replacing the to-be-detected language word with a word with the highest previous return frequency among the multiple words with the minimum edit distance to correct the to-be-detected language word; wherein the preset dictionary is a language dictionary corresponding to the target language.

10. The multi-lingual text detection and correction method of claim 5, wherein, The inputting of the to-be-detected sentence into a preset semantic correction model for semantic correction processing comprises: extracting at least one to-be-corrected word from the to-be-detected sentence with a semantic error; querying a preset dictionary, and taking all candidate words in the preset dictionary with an edit distance from the to-be-corrected word less than or equal to a preset threshold as a candidate set; masking the to-be-corrected word in the to-be-detected sentence with a preset marker, and inputting the to-be-detected sentence after the masking into a preset semantic correction model; The preset semantic correction model predicts a probability of replacing the masked to-be-corrected word with each candidate word in the candidate set, and takes a candidate word with the highest probability value as a correction word.

11. The multi-lingual text detection and correction method of claim 10, wherein, The returning of the to-be-detected text corresponding to the to-be-detected sentence after semantic correction as a detected text comprises: merging the correction word and the to-be-detected sentence; when merging, if the length of the correction word is inconsistent with the length of the corresponding to-be-corrected word or there are multiple correction words in a sentence, deleting the to-be-corrected word in the to-be-detected sentence and then inserting the corresponding correction word; returning the to-be-detected text corresponding to the to-be-detected sentence after merging as a detected text.

12. The multi-lingual text detection and correction method of claim 5, wherein, Before the inputting of the to-be-detected sentence into a preset semantic correction model, the method further comprises: training the preset semantic correction model in the following manner: a preset number of correct target language texts or trunk language texts containing target language words are taken as a training set; texts in the training set are input into the preset semantic error correction model, and the preset semantic error correction model randomly performs masking processing on part of the words in the input texts; for each masked word, the preset semantic error correction model is trained to replace the masked word with a predicted word.

13. A multi-lingual text detection and correction system, characterized by, The system comprises: The identification module is configured to obtain a to-be-detected text, and perform multilingual character recognition on the to-be-detected text to obtain at least one to-be-recognized sentence, wherein the to-be-recognized sentence contains characters of a trunk language and characters of at least one target language, and the trunk language is different from the target language. The detection module is configured to perform language detection on the characters of the target language in the to-be-recognized sentence to obtain to-be-detected language words, and perform spelling detection and semantic detection on the to-be-detected language words. The error correction module is configured to, if at least one of the to-be-detected language words has a spelling error and / or a semantic error, perform corresponding spelling correction and / or semantic correction on the word having the spelling error and / or the semantic error. The detection module is further configured to: input a to-be-recognized sentence containing characters of the target language into a preset language detection model; and perform word segmentation on the input to-be-recognized sentence based on a sequence labeling mechanism, and output the language of the target language words contained in the to-be-recognized sentence. The detection module is further configured to: perform word segmentation on the to-be-recognized sentence to obtain a word segmentation list containing at least one word segmentation, and add preset special characters at the beginning and the end of the word segmentation list to represent the beginning and the end; map each word segmentation in the word segmentation list to a corresponding identification number to obtain an identification number list; input the identification number list into an embedding layer of the preset language detection model to convert it into a first matrix with a first preset dimension; input the first matrix into a multi-layer transformer of the preset language detection model to perform calculation, to output a second matrix with a second preset dimension; input the second matrix into a fully connected layer of the preset language detection model, and perform normalization calculation on the output of the fully connected layer to obtain the language probability of each word segmentation corresponding to the identification number; and determine the language corresponding to each word segmentation according to the language probability of each word segmentation.

14. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the program to implement the steps of the multilingual text detection and error correction method according to any one of claims 1 to 12.

15. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the multilingual text detection and error correction method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • English pinyin recognition method and system for multi-language mixed text

    CN112528649A

  • Chinese text error correction system, method and device and computer readable storage medium

    CN113435186A