Method, device and electronic device for generating punctuation mark prediction model
By generating samples without punctuation marks and punctuation mark sequences, the pre-trained language model is multi-task trained, which solves the problem of insufficient punctuation mark prediction accuracy in the existing technology and improves the readability of speech recognition transcribed text. and punctuation prediction accuracy.
Patent Information
- Application Number
- CN202210823101.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-12
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2042-07-12
AI Technical Summary
Existing punctuation mark prediction models are difficult to effectively utilize the semantic information in training texts in speech recognition scenarios, resulting in insufficient punctuation mark prediction accuracy and text readability.
By obtaining a text collection with punctuation marks, generate text sequences and punctuation mark sequences without punctuation marks, perform mask processing, and combine with pre-trained language models for multi-task training to reduce dependence on punctuation marks and learn punctuation-free marks. Semantic information in text to improve punctuation prediction accuracy.
It improves the accuracy of punctuation prediction and the readability of speech recognition transcribed text, makes full use of training samples through multi-task training, reduces dependence on punctuation, and enhances the semantic understanding ability of the language model.
Smart Images

Figure CN115129877B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device and electronic device for generating a punctuation mark prediction model. Background Art
[0002] In the speech recognition scenario, the input is a piece of audio. The speech recognition system transcribes the input audio word by word into natural language text. After a series of text processing steps and the punctuation prediction model adds punctuation to the text, it becomes a more readable text.
[0003] Taking Chinese as an example, commonly used punctuation marks include commas, periods, question marks, exclamation marks, quotation marks, and dashes. These punctuation marks have multiple functions, such as semantic pauses, sentence segmentation, and emotional reinforcement. They help improve the readability of texts and sometimes play an important role in eliminating text ambiguity. The task of the punctuation prediction model is to understand text without punctuation, predict punctuation marks on the basis of being faithful to the original semantics, improve the quality and readability of texts, and reduce text ambiguity. Summary of the invention
[0004] This disclosure section is provided to introduce concepts in a brief form, which will be described in detail in the detailed description section below. This disclosure section is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for generating a punctuation prediction model, the method comprising: obtaining a text set, wherein the text in the text set contains punctuation marks; for each text in the text set, using the text to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, masking the text in the text sequence, and combining the masked text sequence and the masked character sequence to form a second sample, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds one-to-one to the punctuation marks in the punctuation mark sequence; based on the first sample and the corresponding second sample, training a pre-trained language model to obtain a retrained language model; based on the first sample, training the retrained language model to obtain a punctuation prediction model.
[0006] In a second aspect, an embodiment of the present disclosure provides a device for generating a punctuation prediction model, the device comprising: an acquisition unit, for acquiring a text set, wherein the text in the text set has punctuation marks; a generation unit, for generating, for each text in the text set, a text sequence without punctuation marks and a punctuation mark sequence using the text to form a first sample, masking the text in the text sequence, and forming a second sample with the masked text sequence and the masked character sequence, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds one-to-one to the punctuation marks in the punctuation mark sequence; a first training unit, for training a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model; and a second training unit, for training the retrained language model based on the first sample to obtain a punctuation prediction model.
[0007] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: at least one processor; and a storage device for storing at least one program, wherein when the at least one program is executed by the at least one processor, the at least one processor implements the method for generating a punctuation prediction model as in the first aspect.
[0008] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method for generating a punctuation mark prediction model as in the first aspect.
[0009] The generation method, device and electronic device of the punctuation mark prediction model provided by the embodiments of the present disclosure obtain a text set with punctuation marks; then, for each text in the above text set, the text can be used to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, and the text in the above text sequence is masked, and the masked text sequence and the masked character sequence are combined into a second sample; then, based on the first sample and the corresponding second sample, a pre-trained language model can be trained to obtain a retrained language model; finally, based on the first sample, the retrained language model can be trained to obtain a punctuation mark prediction model. Compared with the existing punctuation prediction model, the language model is first trained with text with punctuation for the semantic understanding task, and then the text without punctuation is used to train the punctuation prediction task. This method allows the language model to be trained with the same training text for both the semantic understanding task and the punctuation prediction task during the training process of the language model, which helps the language model reduce its dependence on punctuation and learn the semantic information in the text without punctuation. At the same time, the multi-task training method (i.e., the combination of the semantic understanding task and the punctuation prediction task) helps to make full use of the training samples and improve the accuracy of punctuation prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0011] Figure 1 is a flowchart of an embodiment of a method for generating a punctuation mark prediction model according to the present disclosure;
[0012] Figure 2 is a schematic diagram of an application scenario of the method for generating a punctuation mark prediction model according to the present disclosure;
[0013] Figure 3 is a flowchart of an embodiment of a language model trained and retrained in the method for generating a punctuation mark prediction model according to the present disclosure;
[0014] Figure 4 is a flowchart of another embodiment of a method for generating a punctuation mark prediction model according to the present disclosure;
[0015] Figure 5 is a flowchart of another embodiment of a language model trained and retrained in the method for generating a punctuation mark prediction model according to the present disclosure;
[0016] Figure 6 is a structural schematic diagram of an embodiment of a device for generating a punctuation mark prediction model according to the present disclosure;
[0017] Figure 7 is an exemplary system architecture in which the method for generating a punctuation mark prediction model according to an embodiment of the present disclosure may be applied;
[0018] Figure 8 It is a schematic diagram of the basic structure of an electronic device provided according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0019] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0020] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0021] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0022] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0023] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0024] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0025] Please refer to Figure 1, which shows the process 100 of an embodiment of the method for generating a punctuation prediction model according to the present disclosure. The method for generating the punctuation prediction model includes the following steps:
[0026] Step 101, obtain a text set.
[0027] In this embodiment, the execution subject of the method for generating the punctuation prediction model can obtain a text set for training. The texts in the above text set usually carry punctuation marks.
[0028] There are pauses before and after a sentence, and it has a certain intonation, indicating a relatively complete meaning. The pauses before, after, or in the middle of a sentence are manifested as time intervals in spoken language and are represented by punctuation marks in written language. Punctuation marks are an organic part of written language and an indispensable auxiliary tool for written language. They can help people express their thoughts and feelings accurately and understand written language. Here, the punctuation marks may include, but are not limited to, at least one of the following: a period (。), a comma (,), a question mark (?), an exclamation mark (!), and a semicolon (、).
[0029] Step 102, for the texts in the text set, use the text to generate a text sequence without punctuation marks and a punctuation mark sequence, form a first sample, perform masking processing on the texts in the text sequence, and form a second sample with the masked text sequence and the masked character sequence.
[0030] In this embodiment, for each text in the above text set, the above execution subject can use the text to generate a text sequence without punctuation marks and a punctuation mark sequence, and form a first sample. Each object in the above text sequence is usually a character in the text. The texts in the above text sequence and the punctuation marks in the above punctuation mark sequence are usually in one-to-one correspondence.
[0031] Specifically, the above text sequence can be expressed as: x = [x1, x2,..., x n , and the above punctuation mark sequence can be expressed as: y = [y1, y2,..., y n , where n represents the length of the input text, that is, the number of characters in the text sequence, x i , i ∈ [1, n], represents the i-th character in the text, and y i , i ∈ [1, n], represents the punctuation mark after the i-th character in the text.
[0032] It should be noted that if there is no punctuation mark after the i-th character, the punctuation mark can be identified by a preset character at this time, for example, "empty" or "null".
[0033] As an example, if the text is "Humility makes people progress, pride makes people fall behind.", the extracted text sequence is: ["humility", "heart", "make", "people", "progress", "step", "pride", "arrogance", "make", "people", "fall behind", "behind"], and the extracted punctuation sequence is: ["null", "null", "null", "null", "null", ","", "null", "null", "null", "null", "."].
[0034] It should be noted that, if the text is: The little cat said: "Little rooster, thank you!", the extracted text sequence is: ["little", "flower", "cat", "said", "little", "rooster", "thank you", "thank you", "you"], and the extracted punctuation sequence is: ["null", "null", "null", ":"", "null", "null", ","", "null", "null", "!" ""]. That is to say, since the text in the above text sequence and the punctuation marks in the above punctuation sequence are usually one-to-one corresponding, if there are two punctuation marks after a character, at this time, the two punctuation marks can be regarded as a whole.
[0035] Afterwards, the execution subject may perform mask processing on the text in the text sequence, and form the masked text sequence and the masked character sequence into a second sample. Here, the execution subject may select a preset proportion (e.g., 10%) of characters from the text sequence as characters to be masked, and then replace the characters to be masked with a mask identifier (mask), original characters or other random characters to obtain a masked text sequence.
[0036] Specifically, the text sequence after the above masking process can be expressed as: x′=[x′1,x′2,...,x′ n ], the above masked character sequence can be expressed as: Where n represents the length of the input text, that is, the number of characters in the text sequence, and x′ i ,i∈[1,n], represents the i-th character in the masked text, Indicates the masked character corresponding to the i-th character in the masked text.
[0037] It should be noted that, if the i-th character in the masked text is an unmasked character, then the corresponding masked character can be identified by a preset character, for example, "empty" or "null".
[0038] As an example, if the text is: "Modesty helps one to make progress, while conceit makes one lag behind.", the text sequence obtained by masking this text can be: ["虚", "mask", "使", "人", "进", "步", "骄", "傲", "哈", "人", "落", "后"], and the masked character sequence is: ["null", "心", "null", "null", "null", "null", "null", "null", "使", "null", "null", "null"].
[0039] Step 103: Based on the first sample and the corresponding second sample, train the pre-trained language model to obtain a re-trained language model.
[0040] In this embodiment, the above-mentioned execution subject can train the pre-trained language model based on the first sample and the corresponding second sample generated in step 102 to obtain a re-trained language model. Here, the pre-trained language model usually has a certain natural language understanding ability, and this language model can be a Masked Language Model (MLM).
[0041] Specifically, the above-mentioned execution subject can use the text sequence without punctuation marks and the punctuation mark sequence in the first sample as the input and expected output of the pre-trained language model respectively to train the pre-trained language model. At the same time, use the masked text sequence and the masked character sequence in the corresponding second sample as the input and expected output of the pre-trained language model respectively to train the pre-trained language model to obtain a re-trained language model.
[0042] Step 104: Based on the first sample, train the re-trained language model to obtain a punctuation prediction model.
[0043] In this embodiment, the above-mentioned execution subject can train the re-trained language model based on the first sample to obtain a punctuation prediction model. It should be noted that the first sample used at this time can be the sample not used in step 103.
[0044] Specifically, the above-mentioned execution subject can use the text sequence without punctuation marks and the punctuation mark sequence in the first sample as the input and expected output of the re-trained language model respectively to train the re-trained language model.
[0045] The method provided by the above-mentioned embodiment of the present disclosure obtains a text set with punctuation marks; then, for each text in the above-mentioned text set, the text can be used to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, and the text in the above-mentioned text sequence is masked, and the masked text sequence and the masked character sequence are combined into a second sample; then, based on the first sample and the corresponding second sample, a pre-trained language model can be trained to obtain a retrained language model; finally, based on the first sample, the above-mentioned retrained language model can be trained to obtain a punctuation mark prediction model. Compared with the existing punctuation prediction model, the language model is first trained with text with punctuation for the semantic understanding task, and then the text without punctuation is used to train the punctuation prediction task. This method allows the language model to be trained with the same training text for both the semantic understanding task and the punctuation prediction task during the training of the language model, which helps the language model reduce its dependence on punctuation and learn the semantic information in the text without punctuation. At the same time, the multi-task training method (i.e., the combination of semantic understanding tasks and punctuation prediction tasks) helps to make full use of training samples, improve the accuracy of punctuation prediction, and then improve the readability of speech recognition transcribed text.
[0046] In some optional implementations, the execution subject may train the retrained language model based on the first sample to obtain a punctuation prediction model in the following manner: the execution subject may input the text sequence without punctuation in the first sample into the retrained language model to obtain a punctuation sequence. Afterwards, the difference between the punctuation sequence in the input first sample and the obtained punctuation sequence may be determined by using a preset first loss function. Finally, the model parameters of the retrained language model may be adjusted based on the difference until the retrained language model converges to obtain a punctuation prediction model. Here, various implementations may be used to adjust the model parameters of the pre-trained language model based on the total difference. For example, the BP (BackPropagation) algorithm and the SGD (Stochastic Gradient Descent) algorithm may be used to adjust the model parameters of the pre-trained language model.
[0047] Continue to see Figure 2 , Figure 2 FIG. 1 is a schematic diagram of an application scenario of the method for generating a punctuation mark prediction model according to this embodiment. Figure 2In the application scenario, the execution subject of the generation of the punctuation mark prediction model obtains the text 201: "The tadpole looks for its mother and talks about five animals: frog, duck, fish, turtle, and goose." The execution subject can generate a text sequence 202 without punctuation marks of the text: "little", "tadpole", "look for", "mother", "mother", "will", "talk", "to", "five", "kinds", "animal", "thing", "green", "frog", "duck", "fish", "crow", "turtle", "goose", and generate a corresponding punctuation mark sequence 203: "null", "null", "null", "null", "null", ","", "null", "null", "null", "null", "null", "null", ","", "null", ","", "null", ","", "null", ","." The execution subject can combine the text sequence 202 and the corresponding punctuation mark sequence 203 into a first sample. Afterwards, the text sequence 202 can be masked to obtain a masked text sequence 204: "small", "mask", "pole", "find", "mom", "mask", "will", "talk", "to", "five", "ha", "animal", "thing", "green", "frog", "duck", "fish", "black", "turtle", "goose", and a masked character sequence 205: "null", "tadpole", "null", "null", "null", "mom", "null", "null", "null", "null", "species", "null", "null", "null", "null", "null", "null", "null", "null", "null", "null". The above-mentioned execution subject can form the masked text sequence 204 and the masked character sequence 205 into a second sample. Then, the above-mentioned execution subject can use the text sequence 202 and the corresponding punctuation sequence 203 as the input and expected output of the pre-trained language model respectively to train the pre-trained language model. At the same time, the masked text sequence 204 and the masked character sequence 205 are used as the input and expected output of the pre-trained language model, respectively, and the pre-trained language model is trained to obtain a retrained language model. Finally, the text sequence 202 and the corresponding punctuation sequence 203 can be used as the input and expected output of the retrained language model, respectively, and the retrained language model is trained to obtain a punctuation prediction model.
[0048] Further references Figure 3 , which shows a process 300 of an embodiment of a method for generating a punctuation mark prediction model by training to obtain a retrained language model. The process 300 of training to obtain a retrained language model includes the following steps:
[0049] Step 301: Input a text sequence without punctuation marks in a first sample into a pre-trained language model to obtain a punctuation mark sequence, and use a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference.
[0050] In this embodiment, the execution subject of the method for generating a punctuation prediction model can input a text sequence without punctuation marks in the first sample into a pre-trained language model to obtain a punctuation mark sequence. Afterwards, a preset first loss function can be used to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as the first difference. Here, the first loss function can be a cross entropy loss function, and the first loss function can be as shown in the following formula (1):
[0051]
[0052] Where N is the total number of texts contained in the text set; M p is the number of punctuation tags that may appear in the punctuation prediction task. For example, if the preset punctuation tags that may appear include comma, period, question mark, exclamation mark, dash, and space (indicating no punctuation), then M p is 6; c refers to one of the preset punctuation tags that may appear; is the true value (Boolean value) of the i-th sample under the c-th class of punctuation label; The predicted probability value (continuous value) of the i-th sample predicted by the model under the c-th class of the punctuation label.
[0053] Step 302: Input the masked text sequence in the corresponding second sample into a pre-trained language model to obtain a predicted masked character sequence, and use a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as the second difference.
[0054] In this embodiment, the execution subject may input the masked text sequence in the corresponding second sample into a pre-trained language model to obtain a predicted masked character sequence. Afterwards, a preset second loss function may be used to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as the second difference. Here, the second loss function may be a cross entropy loss function, and the second loss function may be as shown in the following formula (2):
[0055]
[0056] Where N is the total number of texts contained in the text set; M m is the number of character labels that may appear in the semantic understanding task. For example, if there are 1000 characters in the preset character list, then M m is 1000; c refers to a label among the preset character labels that may appear; is the true value (Boolean value) of the i-th sample under the c-th class of the character label; The predicted probability value (continuous value) of the i-th sample predicted by the model under the c-th class of the character label.
[0057] Step 303: Determine the total difference using the first difference and the second difference.
[0058] In this embodiment, the execution entity may determine the total difference using the first difference determined in step 301 and the second difference determined in step 302. Specifically, the execution entity may determine the total difference as a weighted sum of the first difference and the second difference.
[0059] Step 304: Based on the total difference, adjust the model parameters of the pre-trained language model until the pre-trained language model reaches convergence, thereby obtaining a re-trained language model.
[0060] In this embodiment, the execution entity may adjust the model parameters of the pre-trained language model based on the total difference until the pre-trained language model converges to obtain a re-trained language model.
[0061] Here, various implementations may be used to adjust the model parameters of the pre-trained language model based on the total difference. For example, the BP algorithm and the SGD algorithm may be used to adjust the model parameters of the pre-trained language model.
[0062] In this embodiment, during the model training process, for the punctuation prediction task, the accuracy and recall of each label can be monitored. For the language model prediction task (i.e., the semantic understanding task), the ppl value (perplexity) of the language model can be monitored. When both tasks reach convergence, the model training is terminated to obtain a retrained language model.
[0063] The method provided by the above-mentioned embodiments of the present disclosure uses a preset first loss function and a preset second loss function to respectively determine the differences of the model under the punctuation prediction task and the semantic understanding task during the model training process, and then uses the differences to adjust the model parameters of the model until the model converges, thereby improving the accuracy of the retrained language model.
[0064] Further references Figure 4 , which shows a process 400 of another embodiment of a method for generating a punctuation mark prediction model. The process 400 of the method for generating a punctuation mark prediction model includes the following steps:
[0065] Step 401, obtaining a text collection.
[0066] Step 402, for each text in the text set, using the text, generate a text sequence without punctuation and a punctuation sequence to form a first sample, mask the text in the text sequence, and form the masked text sequence and the masked character sequence to form a second sample.
[0067] In this embodiment, steps 401 - 402 may be performed in a manner similar to steps 101 - 102 , and will not be described in detail herein.
[0068] Step 403: convert uppercase letters in the text sequence into lowercase letters to obtain an all-lowercase text sequence, extract corresponding uppercase and lowercase label sequences, and combine the all-lowercase text sequence and the corresponding uppercase and lowercase label sequences into a third sample.
[0069] In this embodiment, the text may be an English text, which usually includes uppercase letters and lowercase letters. The execution subject of the method for generating a punctuation mark prediction model may convert the uppercase letters in the above text sequence into lowercase letters to obtain an all-lowercase text sequence. It should be noted that the uppercase letters may be English abbreviations, such as CPU, or the first letter may be capitalized, such as Central Processing Unit.
[0070] Afterwards, the corresponding case label sequence can be extracted, and the all-lowercase text sequence and the corresponding case label sequence can be combined into a third sample. Specifically, the above all-lowercase text sequence can be expressed as: x″=[x″1,x″2,...,x″ n ], the corresponding sequence of uppercase and lowercase labels can be expressed as: Where n represents the length of the input text, that is, the number of characters in the text sequence, and x″ i ,i∈[1,n], represents the i-th character in the all-lowercase text, Represents the case label corresponding to the i-th character in the all-lowercase text.
[0071] Here, a first label can be preset to indicate that a character contains all lowercase letters, for example, "0"; a second label can be preset to indicate that a character contains uppercase letters and the uppercase letters are English abbreviations, that is, the character is all uppercase, for example, "1"; a third label can also be preset to indicate that a character contains uppercase letters and the first letter of the character is an uppercase letter, for example, "2".
[0072] As an example, if the text is: "Sometimes your plans don't work out because God has better ones.", the all-lowercase text sequence is: ["sometimes", "your", "plans", "don't", "work", "out", "because", "god", "has", "better", "ones"], and the corresponding uppercase and lowercase label sequence is: ["2", "0", "0", "0", "0", "0", "0", "2", "0", "0", "0"].
[0073] Step 404: train the pre-trained language model based on the first sample, the corresponding second sample, and the corresponding third sample to obtain a retrained language model.
[0074] In this embodiment, the execution subject may train the pre-trained language model based on the first sample and the corresponding second sample generated in step 402 and the corresponding third sample generated in step 403 to obtain a retrained language model. Here, the pre-trained language model is usually a model that has a certain natural language understanding capability, and the language model may be a masked language model.
[0075] Specifically, the execution subject can use the text sequence without punctuation marks and the punctuation mark sequence in the first sample as the input and expected output of the pre-trained language model, and train the pre-trained language model. At the same time, use the masked text sequence and the masked character sequence in the corresponding second sample as the input and expected output of the pre-trained language model, and train the pre-trained language model. Also, use the all-lowercase text sequence and the corresponding uppercase and lowercase label sequence in the corresponding third sample as the input and expected output of the pre-trained language model, and train the pre-trained language model to obtain a retrained language model.
[0076] Step 405: Based on the first sample, the retrained language model is trained to obtain a punctuation mark prediction model.
[0077] In this embodiment, the execution subject may train the retrained language model based on the first sample to obtain a punctuation mark prediction model. It should be noted that the first sample used at this time may be a training sample not used in step 103 .
[0078] Specifically, the execution entity may use the text sequence without punctuation marks and the punctuation mark sequence in the first sample as the input and expected output of the retrained language model, respectively, to train the retrained language model.
[0079] In some cases, while using the first sample for training, the execution entity may also use the all-lowercase text sequence and the corresponding uppercase and lowercase label sequence in the third sample as the input and expected output of the retrained language model, respectively, to train the retrained language model.
[0080] from Figure 4 It can be seen that Figure 1 Compared with the corresponding embodiment, the process 400 of the method for generating the punctuation mark prediction model in this embodiment embodies the steps of forming a third sample from an all-lowercase text sequence and a corresponding uppercase and lowercase label sequence, and using the third sample to train the pre-trained language model. Therefore, the scheme described in this embodiment can add the function of capital letter recovery while training the semantic understanding function and punctuation mark prediction function of the pre-trained language model, so that when an all-lowercase text is input, the punctuation mark of the text can be predicted using the punctuation mark prediction model while realizing the function of capital letter recovery.
[0081] Further references Figure 5 , which shows a process 500 of another embodiment of a method for generating a punctuation mark prediction model by training a language model to be retrained. The process 500 of training a language model to be retrained comprises the following steps:
[0082] Step 501: Input a text sequence without punctuation marks in a first sample into a pre-trained language model to obtain a punctuation mark sequence, and use a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference.
[0083] Step 502: Input the masked text sequence in the corresponding second sample into a pre-trained language model to obtain a predicted masked character sequence, and use a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as the second difference.
[0084] In this embodiment, steps 501-502 may be performed in a manner similar to steps 301-302, and will not be described in detail herein.
[0085] Step 503: Input the all-lowercase text sequence in the corresponding third sample into a pre-trained language model to obtain a predicted uppercase and lowercase label sequence, and use a preset third loss function to determine the difference between the uppercase and lowercase label sequence in the input third sample and the predicted uppercase and lowercase label sequence as the third difference.
[0086] In this embodiment, the execution subject of the method for generating a punctuation prediction model can input the all-lowercase text sequence in the corresponding third sample into a pre-trained language model to obtain a predicted uppercase label sequence. Afterwards, a preset third loss function can be used to determine the difference between the uppercase label sequence in the input third sample and the predicted uppercase label sequence as the third difference. Here, the third loss function can be a cross entropy loss function, and the third loss function can be as shown in the following formula (3):
[0087]
[0088] Where N is the total number of texts contained in the text set; M c is the number of uppercase and lowercase labels (or number of labels) that may appear in the uppercase recovery task. For example, if the preset labels that may appear include all lowercase, all uppercase, and first letter capitalized, then M c is 3; c refers to a type of label among the preset uppercase and lowercase labels that may appear; is the true value (Boolean value) of the i-th sample under the c-th class of the uppercase and lowercase label; The predicted probability value (continuous value) of the i-th sample predicted by the model under the c-th class of the uppercase and lowercase labels.
[0089] Step 504, determining a total difference using the first difference, the second difference, and the third difference.
[0090] In this embodiment, the execution entity may determine the total difference using the first difference determined in step 501, the second difference determined in step 502, and the third difference determined in step 503. Specifically, the execution entity may determine the total difference as a weighted sum of the first difference, the second difference, and the third difference. That is, the execution entity may determine the total difference using the following formula (4):
[0091] Loss = w punc Loss punc +w case Loss case +w mlmLoss mlm (4)
[0092] Among them, Loss punc is the first loss function, Loss mlm is the second loss function, Loss case is the third loss function, w punc is the weight corresponding to the first loss function, w mlm is the weight corresponding to the second loss function, w case is the weight corresponding to the third loss function.
[0093] Step 505 , based on the total difference, adjust the model parameters of the pre-trained language model until the pre-trained language model reaches convergence, thereby obtaining a re-trained language model.
[0094] In this embodiment, step 505 may be performed in a manner similar to step 304, and will not be described in detail herein.
[0095] The method provided by the above-mentioned embodiments of the present disclosure uses a preset first loss function, a preset second loss function and a preset third loss function to respectively determine the differences of the model under punctuation prediction tasks, semantic understanding tasks and uppercase letter restoration tasks during the model training process, and then uses the differences to adjust the model parameters of the model until the model converges, thereby improving the accuracy of the retrained language model.
[0096] Further references Figure 6 As an implementation of the methods shown in the above figures, the present application provides an embodiment of a device for generating a punctuation mark prediction model. Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0097] like Figure 6As shown, the punctuation mark prediction model generation device 600 of this embodiment includes: an acquisition unit 601, a generation unit 602, a first training unit 603 and a second training unit 604. The acquisition unit 601 is used to acquire a text set, wherein the text in the text set has punctuation marks; the generation unit 602 is used to generate a text sequence without punctuation marks and a punctuation mark sequence for each text in the text set, using the text, to form a first sample, mask the text in the text sequence, and form a second sample with the masked text sequence and the masked character sequence, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds to the punctuation marks in the punctuation mark sequence one by one; the first training unit 603 is used to train the pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model; the second training unit 604 is used to train the retrained language model based on the first sample to obtain a punctuation mark prediction model.
[0098] In this embodiment, the specific processing of the acquisition unit 601, the generation unit 602, the first training unit 603 and the second training unit 604 of the punctuation mark prediction model generation device 600 can refer to Figure 1 This corresponds to step 101, step 102, step 103 and step 104 in the embodiment.
[0099] In some optional implementations, the text is an English text; and the punctuation mark prediction model generation device 600 may further include: a conversion unit (not shown in the figure). The conversion unit is used to convert the uppercase letters in the text sequence into lowercase letters to obtain an all-lowercase text sequence, and extract the corresponding uppercase and lowercase label sequences, and form the all-lowercase text sequence and the corresponding uppercase and lowercase label sequences into a third sample.
[0100] In some optional implementations, the first training unit 603 may be further used to train a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model in the following manner: the first training unit 603 may train a pre-trained language model based on the first sample, the corresponding second sample and the corresponding third sample to obtain a retrained language model.
[0101] In some optional implementations, the first training unit 603 can be further used to train a pre-trained language model based on the first sample, the corresponding second sample and the corresponding third sample in the following manner to obtain a retrained language model: the first training unit 603 can input the text sequence without punctuation marks in the first sample into the pre-trained language model to obtain a punctuation mark sequence, and use a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as the first difference; thereafter, the masked text sequence in the corresponding second sample can be input into the pre-trained language model to obtain a predicted masked character sequence, and a preset first loss function can be used to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as the first difference; A second loss function is used to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as the second difference; then, the all-lowercase text sequence in the corresponding third sample can be input into the pre-trained language model to obtain the predicted uppercase and lowercase label sequence, and a preset third loss function is used to determine the difference between the uppercase and lowercase label sequence in the input third sample and the predicted uppercase and lowercase label sequence as the third difference; then, the above-mentioned first difference, the above-mentioned second difference and the above-mentioned third difference can be used to determine the total difference; finally, based on the above-mentioned total difference, the model parameters of the pre-trained language model can be adjusted until the pre-trained language model converges to obtain a retrained language model.
[0102] In some optional implementations, the first training unit 603 may be further used to train a pre-trained language model based on the first sample and the corresponding second sample in the following manner to obtain a retrained language model: the first training unit 603 may input the text sequence without punctuation marks in the first sample into the pre-trained language model to obtain a punctuation mark sequence, and use a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference; thereafter, the masked text sequence in the corresponding second sample may be input into the pre-trained language model to obtain a predicted masked character sequence, and use a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as a second difference; thereafter, the first difference and the second difference may be used to determine the total difference; finally, based on the total difference, the model parameters of the pre-trained language model may be adjusted until the pre-trained language model converges to obtain a retrained language model.
[0103] In some optional implementations, the second training unit 604 may be further used to train the retrained language model based on the first sample to obtain a punctuation prediction model in the following manner: the second training unit 604 may input the text sequence without punctuation in the first sample into the retrained language model to obtain a punctuation sequence, and use a preset first loss function to determine the difference between the punctuation sequence in the input first sample and the obtained punctuation sequence; then, based on the difference, the model parameters of the retrained language model may be adjusted until the retrained language model converges to obtain a punctuation prediction model.
[0104] Please refer to Figure 7 , Figure 7 An exemplary system architecture is shown in which the method for generating a punctuation mark prediction model according to an embodiment of the present disclosure can be applied.
[0105] like Figure 7 As shown, the system architecture may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 is used to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. The network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0106] The terminal devices 701, 702, and 703 can interact with the server 705 through the network 704 to receive or send messages, etc. For example, the terminal devices 701, 702, and 703 can obtain a pre-trained language model from the server 705. Various client applications can be installed on the terminal devices 701, 702, and 703, such as speech recognition applications, text processing applications, and instant messaging software.
[0107] Terminal devices 701, 702, and 703 can obtain a text set with punctuation marks; then, for each text in the above text set, the text can be used to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, and the text in the above text sequence is masked, and the masked text sequence and the masked character sequence are combined into a second sample; then, based on the first sample and the corresponding second sample, a pre-trained language model can be trained to obtain a retrained language model; finally, based on the first sample, the retrained language model can be trained to obtain a punctuation mark prediction model.
[0108] Terminal devices 701, 702, and 703 can be hardware or software. When terminal devices 701, 702, and 703 are hardware, they can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) players, laptop computers, and desktop computers, etc. When terminal devices 701, 702, and 703 are software, they can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules (for example, software or software modules used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0109] The server 705 may be a server that provides various services, such as receiving a text set sent by the terminal devices 701, 702, and 703, and then, for each text in the text set, using the text, generating a text sequence without punctuation and a punctuation sequence to form a first sample, masking the text in the text sequence, and forming a second sample with the masked text sequence and the masked character sequence; then, based on the first sample and the corresponding second sample, the pre-trained language model may be trained to obtain a retrained language model; finally, based on the first sample, the retrained language model may be trained to obtain a punctuation prediction model. The server 705 may send the generated punctuation prediction model to the terminal devices 701, 702, and 703.
[0110] It should be noted that the method for generating a punctuation mark prediction model provided in the embodiment of the present disclosure can be executed by a terminal device, and accordingly, the device for generating a punctuation mark prediction model can be set in the terminal devices 701, 702, and 703. In addition, the method for generating a punctuation mark prediction model provided in the embodiment of the present disclosure can also be executed by a server 705, and accordingly, the device for generating a punctuation mark prediction model can be set in the server 705.
[0111] It should also be noted that if the terminal devices 701, 702, and 703 have pre-trained language models stored locally, the server 705 and the network 704 may not exist in the above exemplary system architecture; if the server 705 has a text collection stored locally, the terminal devices 701, 702, 703 and the network 704 may not exist in the above exemplary system architecture.
[0112] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0113] Reference below Figure 8 , which shows an electronic device (eg, Figure 7 The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0114] like Figure 8 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 are also stored. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0115] Typically, the following devices may be connected to the I / O interface 805: input devices 806 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 808 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 809. The communication device 809 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0116] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 809, or installed from a storage device 808, or installed from a ROM 802. When the computer program is executed by the processing device 801, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0117] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0118] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0119] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0120] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a text set, wherein the text in the text set has punctuation marks; for each text in the text set, uses the text to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, masks the text in the text sequence, and forms a second sample with the masked text sequence and the masked character sequence, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds one-to-one to the punctuation marks in the punctuation mark sequence; trains a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model; and trains the retrained language model based on the first sample to obtain a punctuation mark prediction model.
[0121] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0122] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0123] According to one or more embodiments of the present disclosure, a method for generating a punctuation prediction model is provided, the method comprising: obtaining a text set, wherein the text in the text set contains punctuation marks; for each text in the text set, using the text to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, masking the text in the text sequence, and forming a second sample with the masked text sequence and the masked character sequence, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds one-to-one to the punctuation marks in the punctuation mark sequence; based on the first sample and the corresponding second sample, training a pre-trained language model to obtain a retrained language model; based on the first sample, training the retrained language model to obtain a punctuation prediction model.
[0124] According to one or more embodiments of the present disclosure, the text is an English text; and after using the text to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, the method further includes: converting uppercase letters in the text sequence into lowercase letters to obtain an all-lowercase text sequence, and extracting corresponding uppercase and lowercase label sequences, and forming a third sample with the all-lowercase text sequence and the corresponding uppercase and lowercase label sequences.
[0125] According to one or more embodiments of the present disclosure, a pre-trained language model is trained based on a first sample and a corresponding second sample to obtain a retrained language model, including: based on the first sample, the corresponding second sample and the corresponding third sample, the pre-trained language model is trained to obtain a retrained language model.
[0126] According to one or more embodiments of the present disclosure, a pre-trained language model is trained based on a first sample, a corresponding second sample, and a corresponding third sample to obtain a retrained language model, including: inputting a text sequence without punctuation marks in the first sample into the pre-trained language model to obtain a punctuation mark sequence, using a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference; inputting a masked text sequence in the corresponding second sample into the pre-trained language model to obtain a predicted masked character sequence, using a preset second loss function to determine the input The difference between the masked character sequence in the second sample and the predicted masked character sequence is taken as the second difference; the all-lowercase text sequence in the corresponding third sample is input into the pre-trained language model to obtain the predicted uppercase and lowercase label sequence, and the difference between the uppercase and lowercase label sequence in the input third sample and the predicted uppercase and lowercase label sequence is determined as the third difference using the preset third loss function; the total difference is determined using the first difference, the second difference and the third difference; based on the total difference, the model parameters of the pre-trained language model are adjusted until the pre-trained language model reaches convergence to obtain a retrained language model.
[0127] According to one or more embodiments of the present disclosure, a pre-trained language model is trained based on a first sample and a corresponding second sample to obtain a retrained language model, including: inputting a text sequence without punctuation marks in the first sample into the pre-trained language model to obtain a punctuation mark sequence, using a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference; inputting a masked text sequence in the corresponding second sample into the pre-trained language model to obtain a predicted masked character sequence, using a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as a second difference; using the above-mentioned first difference and the above-mentioned second difference to determine the total difference; based on the above-mentioned total difference, adjusting the model parameters of the pre-trained language model until the pre-trained language model reaches convergence to obtain a retrained language model.
[0128] According to one or more embodiments of the present disclosure, the above-mentioned retrained language model is trained based on the first sample to obtain a punctuation prediction model, including: inputting a text sequence without punctuation marks in the first sample into the above-mentioned retrained language model to obtain a punctuation mark sequence, using a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence; based on the above-mentioned difference, adjusting the model parameters of the above-mentioned retrained language model until the above-mentioned retrained language model reaches convergence to obtain a punctuation mark prediction model.
[0129] According to one or more embodiments of the present disclosure, a device for generating a punctuation mark prediction model is provided, the device comprising: an acquisition unit, for acquiring a text set, wherein the text in the above text set contains punctuation marks; a generation unit, for generating, for each text in the above text set, a text sequence without punctuation marks and a punctuation mark sequence using the text to form a first sample, masking the text in the above text sequence, and forming a second sample with the masked text sequence and the masked character sequence, wherein each object in the above text sequence is a character in the text, and the text in the above text sequence corresponds one-to-one to the punctuation marks in the above punctuation mark sequence; a first training unit, for training a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model; and a second training unit, for training the retrained language model based on the first sample to obtain a punctuation mark prediction model.
[0130] According to one or more embodiments of the present disclosure, the text is an English text; and the device also includes: a conversion unit, which is used to convert uppercase letters in the above text sequence into lowercase letters to obtain an all-lowercase text sequence, and extract corresponding uppercase and lowercase label sequences, and combine the all-lowercase text sequence and the corresponding uppercase and lowercase label sequences into a third sample.
[0131] According to one or more embodiments of the present disclosure, the first training unit is further used to train a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model in the following manner: based on the first sample, the corresponding second sample and the corresponding third sample, the pre-trained language model is trained to obtain a retrained language model.
[0132] According to one or more embodiments of the present disclosure, the first training unit is further used to train the pre-trained language model based on the first sample, the corresponding second sample and the corresponding third sample in the following manner to obtain a retrained language model: inputting the text sequence without punctuation marks in the first sample into the pre-trained language model to obtain a punctuation mark sequence, using a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as the first difference; inputting the masked text sequence in the corresponding second sample into the pre-trained language model to obtain a predicted masked character sequence, using a preset second ... function, determining the difference between the masked character sequence in the input second sample and the predicted masked character sequence as the second difference; inputting the all-lowercase text sequence in the corresponding third sample into the pre-trained language model to obtain the predicted uppercase and lowercase label sequence, using a preset third loss function, determining the difference between the uppercase and lowercase label sequence in the input third sample and the predicted uppercase and lowercase label sequence as the third difference; using the above-mentioned first difference, the above-mentioned second difference and the above-mentioned third difference, determining the total difference; based on the above-mentioned total difference, adjusting the model parameters of the pre-trained language model until the pre-trained language model reaches convergence, thereby obtaining a retrained language model.
[0133] According to one or more embodiments of the present disclosure, the first training unit is further used to train a pre-trained language model based on a first sample and a corresponding second sample in the following manner to obtain a retrained language model: input a text sequence without punctuation marks in the first sample into the pre-trained language model to obtain a punctuation mark sequence, and use a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference; input a masked text sequence in the corresponding second sample into the pre-trained language model to obtain a predicted masked character sequence, and use a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as a second difference; use the above-mentioned first difference and the above-mentioned second difference to determine the total difference; based on the above-mentioned total difference, adjust the model parameters of the pre-trained language model until the pre-trained language model converges to obtain a retrained language model.
[0134] According to one or more embodiments of the present disclosure, the second training unit is further used to train the above-mentioned retrained language model based on the first sample in the following manner to obtain a punctuation prediction model: input the text sequence without punctuation marks in the first sample into the above-mentioned retrained language model to obtain a punctuation mark sequence, and use a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence; based on the above-mentioned difference, adjust the model parameters of the above-mentioned retrained language model until the above-mentioned retrained language model reaches convergence to obtain a punctuation mark prediction model.
[0135] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit does not limit the unit itself in some cases. For example, an acquisition unit may also be described as a "unit for acquiring a text collection".
[0136] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0137] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0138] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0139] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0140] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for generating a punctuation prediction model, characterized in that: include: Acquire a text set, wherein the text in the text set contains punctuation marks; For each text in the text set, using the text, generating a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, performing masking on the text in the text sequence, and forming a second sample with the masked text sequence and the masked character sequence, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds to the punctuation marks in the punctuation mark sequence one by one; Based on the first sample and the corresponding second sample, a pre-trained language model is trained to obtain a retrained language model, including: taking a text sequence without punctuation marks and a punctuation mark sequence in the first sample as an input and an expected output of the pre-trained language model, respectively, and training the pre-trained language model; taking a masked text sequence and a masked character sequence in the corresponding second sample as an input and an expected output of the pre-trained language model, respectively, and training the pre-trained language model to obtain a retrained language model; Based on the first sample, the retrained language model is trained to obtain a punctuation prediction model, including: taking a text sequence without punctuation and a punctuation sequence in the first sample as input and expected output of the retrained language model respectively, and training the retrained language model.
2. The method according to claim 1, characterized in that The text is in English; as well as After using the text to generate a text sequence without punctuation marks and a punctuation mark sequence to form a first sample, the method further includes: The uppercase letters in the text sequence are converted into lowercase letters to obtain an all-lowercase text sequence, and the corresponding uppercase and lowercase label sequences are extracted, and the all-lowercase text sequence and the corresponding uppercase and lowercase label sequences are combined into a third sample.
3. The method according to claim 2, characterized in that The method of training a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model includes: Based on the first sample, the corresponding second sample and the corresponding third sample, the pre-trained language model is trained to obtain a retrained language model.
4. The method according to claim 3, characterized in that The method of training a pre-trained language model based on the first sample, the corresponding second sample, and the corresponding third sample to obtain a retrained language model includes: Inputting a text sequence without punctuation marks in the first sample into a pre-trained language model to obtain a punctuation mark sequence, and using a preset first loss function to determine a difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference; Inputting the masked text sequence in the corresponding second sample into a pre-trained language model to obtain a predicted masked character sequence, and using a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as a second difference; Input the all-lowercase text sequence in the corresponding third sample into the pre-trained language model to obtain a predicted uppercase and lowercase label sequence, and use a preset third loss function to determine the difference between the uppercase and lowercase label sequence in the input third sample and the predicted uppercase and lowercase label sequence as a third difference; determining a total difference using the first difference, the second difference, and the third difference; Based on the total difference, model parameters of the pre-trained language model are adjusted until the pre-trained language model reaches convergence, thereby obtaining a re-trained language model.
5. The method according to claim 1, characterized in that The method of training a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model includes: Inputting a text sequence without punctuation marks in the first sample into a pre-trained language model to obtain a punctuation mark sequence, and using a preset first loss function to determine a difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence as a first difference; Inputting the masked text sequence in the corresponding second sample into a pre-trained language model to obtain a predicted masked character sequence, and using a preset second loss function to determine the difference between the masked character sequence in the input second sample and the predicted masked character sequence as a second difference; determining a total difference using the first difference and the second difference; Based on the total difference, model parameters of the pre-trained language model are adjusted until the pre-trained language model reaches convergence, thereby obtaining a re-trained language model.
6. The method according to any one of claims 1 to 5, characterized in that: The step of training the retrained language model based on the first sample to obtain a punctuation mark prediction model includes: Inputting the text sequence without punctuation marks in the first sample into the retrained language model to obtain a punctuation mark sequence, and using a preset first loss function to determine the difference between the punctuation mark sequence in the input first sample and the obtained punctuation mark sequence; Based on the difference, the model parameters of the retrained language model are adjusted until the retrained language model reaches convergence to obtain a punctuation mark prediction model.
7. A device for generating a punctuation mark prediction model, characterized in that: include: An acquisition unit, used for acquiring a text set, wherein the text in the text set contains punctuation marks; A generating unit is used for generating a text sequence without punctuation marks and a punctuation mark sequence using each text in the text set to form a first sample, performing masking on the text in the text sequence, and forming a second sample with the masked text sequence and the masked character sequence, wherein each object in the text sequence is a character in the text, and the text in the text sequence corresponds to the punctuation marks in the punctuation mark sequence one by one; The first training unit is used to train a pre-trained language model based on the first sample and the corresponding second sample to obtain a retrained language model, including: taking a text sequence without punctuation marks and a punctuation mark sequence in the first sample as an input and an expected output of the pre-trained language model, respectively, to train the pre-trained language model; taking a masked text sequence and a masked character sequence in the corresponding second sample as an input and an expected output of the pre-trained language model, respectively, to train the pre-trained language model to obtain a retrained language model; The second training unit is used to train the retrained language model based on the first sample to obtain a punctuation prediction model, including: taking the text sequence without punctuation and the punctuation sequence in the first sample as the input and expected output of the retrained language model respectively, and training the retrained language model.
8. The device according to claim 7, characterized in that The text is in English; as well as The device also includes: The conversion unit is used to convert the uppercase letters in the text sequence into lowercase letters to obtain an all-lowercase text sequence, extract the corresponding uppercase and lowercase label sequences, and form the all-lowercase text sequence and the corresponding uppercase and lowercase label sequences into a third sample.
9. An electronic device, characterized in that: include: at least one processor; a storage device having at least one program stored thereon, When the at least one program is executed by the at least one processor, the at least one processor implements the method according to any one of claims 1 to 6.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
