Text generation method and device, electronic equipment and storage medium

By using the same prediction strategy to process multiple texts to be predicted, the problem of high text generation cost is solved, achieving high-quality text generation and cost reduction.

CN115238656BActive Publication Date: 2025-12-05BEIJING XIAOMI MOBILE SOFTWARE CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210878596.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-25
Publication Date
2025-12-05
Estimated Expiration
2042-07-25

AI Technical Summary

Technical Problem

Existing technologies suffer from high costs in text generation, especially when using ensemble learning neural network models, where training and deploying multiple learners leads to high costs and low efficiency.

Method used

The same prediction strategy is used to predict multiple texts to be predicted. By obtaining the transformed text of the source text, multiple texts to be predicted are determined, and the probability of each predicted sub-text item is obtained by using the prediction model, and finally the target text is generated.

Benefits of technology

While ensuring the quality of text generation, it reduces the cost of text generation and improves execution efficiency, avoiding complex multi-model fusion methods and high costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115238656B_ABST
    Figure CN115238656B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a text generation method and device, electronic equipment and storage medium. The method comprises: obtaining a transformed text corresponding to a source text; determining a plurality of to-be-predicted texts based on the source text and the transformed text; performing prediction processing on each to-be-predicted text through a same prediction strategy to obtain a probability of each predicted subtext item corresponding to each to-be-predicted text, the probability of the predicted subtext item representing a sub-probability of the predicted subtext item being predicted as each candidate subtext in a text library; and obtaining a target text corresponding to the source text based on the probability of each predicted subtext item corresponding to each to-be-predicted text. The method can ensure the quality of text generation, reduce the cost of text generation, and improve the execution efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of artificial intelligence, and particularly relates to a text generation method and device, electronic equipment and storage medium. BACKGROUND

[0002] With the rapid development of artificial intelligence technology, great convenience has been brought to people's production and life. For example, in the text generation scene, through a series of processing of the source text by artificial intelligence technology, the target text corresponding to the source text can be generated to meet the actual needs of people.

[0003] However, in the related art, when generating text, in order to improve the quality of text generation, there is a problem of high cost of text generation. SUMMARY

[0004] In order to overcome the problems in the related art, the present disclosure provides a text generation method and device, electronic equipment and storage medium.

[0005] According to a first aspect of an embodiment of the present disclosure, a text generation method is provided, comprising:

[0006] obtaining a transformed text corresponding to a source text;

[0007] determining a plurality of to-be-predicted texts based on the source text and the transformed text;

[0008] performing prediction processing on each of the to-be-predicted texts by using a same prediction strategy to obtain a probability of each prediction subtext item corresponding to each of the to-be-predicted texts, the probability of the prediction subtext item representing a sub-probability of the prediction subtext item being predicted as each candidate subtext in a text library;

[0009] obtaining a target text corresponding to the source text based on the probability of each prediction subtext item corresponding to each of the to-be-predicted texts.

[0010] In some embodiments, the obtaining of the transformed text corresponding to the source text comprises:

[0011] replacing a target subtext in the source text by using a preset text object to obtain a transformed text.

[0012] In some embodiments, the determining of the plurality of to-be-predicted texts based on the source text and the transformed text comprises:

[0013] determining a plurality of to-be-predicted texts from the source text and all transformed texts based on a number of target subtexts included in the source text, wherein the all transformed texts are obtained after replacing all target subtexts in the source text by using a preset text object.

[0014] In some embodiments, the number of target subtexts included in the source text is used to determine a plurality of to-be-predicted texts from the source text and all transformed texts, including:

[0015] When the number of target subtexts included in the source text is less than or equal to a first number, the source text and all transformed texts are determined as the to-be-predicted texts; or

[0016] When the number of target subtexts included in the source text is greater than the first number, a second number of texts are selected from a set of texts composed of the source text and all transformed texts as the to-be-predicted texts.

[0017] In some embodiments, the target text corresponding to the source text is obtained based on the probability of each predicted subtext item corresponding to each to-be-predicted text, including:

[0018] The probability of each candidate subtext corresponding to the same predicted subtext item is obtained based on the sub-probability of the same candidate subtext corresponding to the same predicted subtext item.

[0019] From the probabilities of each candidate subtext corresponding to the same predicted subtext item, the candidate subtext with the maximum probability is selected as the information of the corresponding predicted subtext item.

[0020] The target text corresponding to the source text is obtained based on the information of each predicted subtext item.

[0021] In some embodiments, each to-be-predicted text is processed by a same prediction strategy to obtain the probability of each predicted subtext item corresponding to each to-be-predicted text, including:

[0022] Each to-be-predicted text is processed by a same prediction model to obtain the probability of each predicted subtext item corresponding to each to-be-predicted text.

[0023] In some embodiments, the training method of the prediction model includes:

[0024] A sample data set is obtained, each sample data in the sample data set including a sample transformed text corresponding to a sample source text and a sample target text corresponding to the sample source text;

[0025] The sample data set is used to train a neural network model to be trained to obtain the prediction model.

[0026] According to a second aspect of the embodiments of the present disclosure, a text generation apparatus is provided, including:

[0027] An acquisition module configured to acquire a transformed text corresponding to a source text;

[0028] A determination module configured to determine a plurality of to-be-predicted texts based on the source text and the transformed text;

[0029] A probability prediction module configured to perform prediction processing on each of the to-be-predicted texts respectively by using a same prediction strategy, to obtain a probability of each predicted subtext item corresponding to each of the to-be-predicted texts, the probability of the predicted subtext item representing a sub-probability of the predicted subtext item being predicted as each candidate subtext in a text library;

[0030] A target text generation module configured to obtain a target text corresponding to the source text based on the probability of each predicted subtext item corresponding to each of the to-be-predicted texts.

[0031] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising:

[0032] A memory having a computer program stored thereon;

[0033] A processor configured to execute the computer program in the memory to implement the steps of the text generation method provided in the first aspect of the present disclosure.

[0034] According to a fourth aspect of an embodiment of the present disclosure, a computer readable storage medium having computer program instructions stored thereon is provided, the program instructions being executed by a processor to implement the steps of the text generation method provided in the first aspect of the present disclosure.

[0035] The technical solution provided by the embodiments of the present disclosure can have the following beneficial effects: after acquiring a transformed text corresponding to a source text, a plurality of to-be-predicted texts can be determined based on the source text and the transformed text, then prediction processing can be performed on each of the to-be-predicted texts respectively by using a same prediction strategy, to obtain a probability of each predicted subtext item corresponding to each of the to-be-predicted texts, the probability of the predicted subtext item representing a sub-probability of the predicted subtext item being predicted as each candidate subtext in a text library, and finally a target text corresponding to the source text can be obtained based on the probability of each predicted subtext item corresponding to each of the to-be-predicted texts. Since the same prediction strategy can be used to perform prediction processing on the plurality of to-be-predicted texts, and the target text is obtained according to the prediction results, the quality of the generated text is ensured by the prediction results of the plurality of to-be-predicted texts, the cost of text generation is reduced and the execution efficiency is improved by using the same prediction strategy, and therefore, the method of the embodiments of the present disclosure can ensure the quality of the generated text while reducing the cost of text generation and improving the execution efficiency.

[0036] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and serve to explain the principles of the present disclosure, in which, like reference numerals designate corresponding parts throughout the several views.

[0038] Figure 1 is a flowchart of a text generation method according to an exemplary embodiment.

[0039] Figure 2 is a flowchart of another text generation method according to an exemplary embodiment.

[0040] Figure 3 is a block diagram of a text generation apparatus according to an exemplary embodiment.

[0041] Figure 4 is a structural schematic diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0042] The exemplary embodiments will be described in detail herein below with reference to the drawings. In the following description, the same drawings reference numbers are used to denote like elements throughout the several views. The embodiments described in the following exemplary embodiments are not representative of all embodiments consistent with the present disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0043] It should be noted that all actions of acquiring signals, information or data in this application are carried out in compliance with the corresponding data protection regulations and policies of the country where the device is located, and with the authorization of the owner of the corresponding device.

[0044] As mentioned in the background, in the related art, when text generation is performed, in order to improve the quality of text generation, there is a problem of high cost of text generation.

[0045] In the related art, a neural network model based on ensemble learning can be used to reduce prediction bias, improve model generalization ability, and achieve better text generation effect. Ensemble learning is a machine learning method that combines multiple learners to make collaborative decisions. By integrating the decision results of multiple learners, prediction bias can be effectively reduced, model generalization ability can be improved, and better results than single models can be achieved. However, in production practice, training and deploying multiple learners results in high cost, high requirements for model structure and multi-model fusion methods, complex methods, and low running efficiency of multiple learners.

[0046] Therefore, the embodiments of the present disclosure provide a text generation method and device, an electronic device and a storage medium, which can use the same prediction strategy to predict multiple texts to be predicted, and finally obtain a target text according to the prediction results, thereby reducing the cost of text generation and improving the execution efficiency while ensuring the quality of text generation.

[0047] Before the text generation method of the embodiments of the present disclosure is described in detail, the text generation scenario of the embodiments of the present disclosure is exemplarily described.

[0048] Exemplarily, the text generation scenario can be a text translation scenario, for example, translating a Chinese text into a corresponding English text, for example, translating a Chinese text into a corresponding German text, and translating a Korean text into a corresponding English text. In the text translation scenario, the text before translation can be understood as a source text, and the text after translation can be understood as a target text.

[0049] Exemplarily, the text generation scenario can also be an abstract generation scenario, for example, extracting corresponding abstract information from a paragraph or an article. In the abstract generation scenario, the paragraph or the article to be abstracted can be understood as a source text, and the final abstract can be understood as a target text.

[0050] Figure 1 is a flowchart of a text generation method according to an exemplary embodiment, as shown in Figure 1 The text generation method can be used in an electronic device, for example, a terminal device such as a mobile phone, a camera, a notebook, a tablet computer, a smart wearable device, etc., and a server. The text generation method includes:

[0051] S110, obtaining a transformed text corresponding to a source text.

[0052] In the embodiments of the present disclosure, the source text to be generated can be transformed to obtain a transformed text corresponding to the source text.

[0053] In some embodiments, the transformation process can be a process of replacing part of the source text with a preset text object. In this case, the source text corresponding to the transformed text is obtained, which can specifically include the following steps:

[0054] The target subtext in the source text is replaced with the preset text object to obtain a transformed text.

[0055] Optionally, the preset text object can be a preset mask. Optionally, the preset text object can be some special mark symbol.

[0056] In the embodiments of the present disclosure, the source text can include multiple subtexts. Among them, the target subtext can be understood as the subtext to be replaced in the source text.

[0057] In the embodiments of the present disclosure, after the replacement of a target subtext is completed, a transformed text can be generated. Among them, the target subtext can include a subtext.

[0058] For example, if the source text is a sentence "today is Sunday", the subtexts can include "today", "is" and "Sunday". At this time, the target subtext can be any one of the three texts "today", "is" and "Sunday", so that the mask <mask>After substitution is performed on any of the target subtexts, a transformed text is obtained. For example, the transformed text <mask>"Sunday", "Today <mask>Sunday, and "Today is <mask>".

[0059] It should be noted that in some embodiments, when the number of subtexts included in the source text is large, in order to simplify the subsequent processing process, a plurality of subtexts can also be combined to be regarded as a target subtext, for example, replacing "today is" in the sentence "today is a suitable day for outing" with a mask <mask>i.e. to obtain <mask>"Sunday is suitable for going out for a walk" is the transformed text.

[0060] The plurality of texts included in the source text can be processed by using a word segmentation algorithm on the source text.

[0061] It can be understood that in the application to the summary generation scenario, each subtext included in the source text can also be determined, so that one or more sentences in an article can be determined as the target subtext according to actual needs.

[0062] S120, determining a plurality of to-be-predicted texts based on the source text and the transformed text.

[0063] In the embodiments of the present disclosure, since the number of source texts is one, the transformed text can be obtained by transforming the source text, so that a plurality of to-be-predicted texts for subsequent processing can be generated.

[0064] In the embodiments of the present disclosure, the to-be-predicted text can be determined from the transformed text alone, or from the source text and the transformed text.

[0065] It can be understood that the more the number of to-be-predicted texts, the more the number of times of processing by applying the prediction strategy, and the higher the quality of subsequent text generation. However, the more the number of to-be-predicted texts, the longer the overall execution time of the text generation method, so a trade-off can be made between the two. Therefore, in some embodiments, determining a plurality of to-be-predicted texts based on the source text and the transformed text can include the steps of:

[0066] Based on the number of target subtexts included in the source text, a plurality of to-be-predicted texts are determined from the source text and all transformed texts, wherein all transformed texts are obtained by respectively replacing all target subtexts in the source text by using a preset text object.

[0067] Replacing one target subtext in the source text can obtain one transformed text, so that the number of transformed texts can be generated according to the number of target subtexts, for example, if the number of target subtexts is N, there can be N+1 to-be-predicted texts in total.

[0068] Therefore, in the embodiments of the present disclosure, a plurality of to-be-predicted texts can be determined from the source text and all transformed texts based on the number of target subtexts included in the source text.

[0069] S130, respectively predict each to-be-predicted text by using the same prediction strategy to obtain the probability of each predicted subtext item corresponding to each to-be-predicted text, the probability of the predicted subtext item representing the sub-probability of the predicted subtext item being predicted as each candidate subtext in the text library.

[0070] In the embodiments of the present disclosure, the prediction strategy can be a prediction algorithm or a trained prediction model.

[0071] The predicted subtext item can be understood as each text part constituting the target text.

[0072] In the translation scenario, a translated sentence is composed of multiple predicted translation words, and the position of each translation word can be regarded as a predicted subtext item of the generated translation text.

[0073] In the summary generation scenario, a generated summary is composed of multiple predicted short sentences, and the position of each predicted short sentence can be regarded as a predicted subtext item of the generated summary.

[0074] For example, for the source text "today is Sunday", the generated English target text is composed of three words, each of which corresponds to a predicted subtext item, for example, can be recorded as predicted subtext item t1, predicted subtext item t2 and predicted subtext item t3 respectively.

[0075] In the embodiments of the present disclosure, after respectively predicting each to-be-predicted text by using the same prediction strategy, the probability of each predicted subtext item of each to-be-predicted text can be obtained.

[0076] For the translation scenario, the text library is a preset word library, and the candidate subtext can be each word in the word library.

[0077] With the foregoing example, after predicting the to-be-predicted text "today is Sunday" by using the prediction strategy, the sub-probabilities of each sub-text item in the three prediction sub-text items t1, t2 and t3 corresponding to the to-be-predicted text "today is Sunday" being predicted as each candidate word in the word library can be obtained, for example, at the t1 position, the sub-probability of being predicted as the candidate word "today" is 0.92, the sub-probability of being predicted as the candidate word "yesterday" is 0.07, the sub-probability of being predicted as the candidate word "weather" is 0.01, and the sub-probability of being predicted as other candidate words is 0. Wherein, 0.92, 0.07, 0.01 and 0 are respectively the sub-probabilities of each sub-text item in the t1 prediction sub-text item corresponding to the to-be-predicted text "today is Sunday". Similarly, the sub-probabilities of each sub-text item in the t2 prediction sub-text item corresponding to the to-be-predicted text "today is Sunday" and the sub-probabilities of each sub-text item in the t3 prediction sub-text item can also be obtained.

[0078] Further, by using the same prediction strategy to predict other to-be-predicted texts, the probabilities of each prediction sub-text item corresponding to the other to-be-predicted texts can also be obtained.

[0079] S140, based on the probabilities of each prediction sub-text item corresponding to each to-be-predicted text, the target text corresponding to the source text is obtained.

[0080] In the embodiments of the present disclosure, after obtaining the probabilities of each prediction sub-text item corresponding to each to-be-predicted text, the probabilities of each prediction sub-text item corresponding to each to-be-predicted text can be further processed, so as to finally obtain the target text corresponding to the source text.

[0081] With the above method, after obtaining the transformed text corresponding to the source text, a plurality of to-be-predicted texts can be determined based on the source text and the transformed text, and then each to-be-predicted text is predicted by using the same prediction strategy to obtain the probabilities of each prediction sub-text item corresponding to each to-be-predicted text. The probability of the prediction sub-text item represents the sub-probability of the prediction sub-text item being predicted as each candidate sub-text in the text library. Finally, the target text corresponding to the source text can be obtained based on the probabilities of each prediction sub-text item corresponding to each to-be-predicted text. Since the same prediction strategy can be used to predict each to-be-predicted text, and the target text can be obtained according to the prediction result, the quality of text generation is ensured by the prediction results of the plurality of to-be-predicted texts, the cost of text generation is reduced, and the execution efficiency is improved by using the same prediction strategy. Therefore, the method of the embodiments of the present disclosure can ensure the quality of text generation while reducing the cost of text generation and improving the execution efficiency.

[0082] Figure 2 is a flowchart of another text generation method according to an example embodiment, as Figure 2 As shown, the text generation method can be used in an electronic device, which can be a terminal device such as a mobile phone, a camera, a notebook, a tablet computer, a smart wearable device, and the like, and a server, for example. The text generation method includes:

[0083] S210, obtaining a transformed text corresponding to the source text.

[0084] The detailed process of step S210 can refer to the specific description of step S110 in the foregoing embodiments, which will not be described here again.

[0085] S220, determining a plurality of to-be-predicted texts from the source text and all the transformed texts based on the number of target subtexts included in the source text, wherein the all the transformed texts are obtained after all the target subtexts in the source text are replaced by the preset text object respectively.

[0086] In some embodiments, determining the plurality of to-be-predicted texts from the source text and all the transformed texts based on the number of target subtexts included in the source text can include the steps of:

[0087] When the number of target subtexts included in the source text is less than or equal to a first number, the source text and all the transformed texts are determined as the to-be-predicted texts; or

[0088] When the number of target subtexts included in the source text is greater than the first number, a second number of texts are selected from a text set composed of the source text and all the transformed texts as the to-be-predicted texts.

[0089] In the embodiments of the present disclosure, if the number of target subtexts is small, for example, less than or equal to the first number, it can be considered that even if the source text and all the transformed texts are used as the to-be-predicted texts, the time for finally applying the prediction strategy for prediction processing is within an acceptable range. At this time, in order to improve the quality of subsequent text generation as much as possible, the source text and all the transformed texts can be determined as the to-be-predicted texts.

[0090] If the number of target subtexts is large, for example, greater than the first number, it can be considered that if the source text and all the transformed texts are used as the to-be-predicted texts, the time for finally applying the prediction strategy for prediction processing is long, which can affect the overall length of the text generation method and reduce the user experience. At this time, in order to improve the quality of subsequent text generation as much as possible while reducing the overall length of the text generation method and improving the user experience, a second number of texts can be selected from a text set composed of the source text and all the transformed texts as the to-be-predicted texts.

[0091] It should be noted that the first quantity and the second quantity can be the same or different, and the embodiments of the present disclosure do not make any limitation.

[0092] In addition, it should also be noted that if the source text includes a target subtext quantity greater than the first quantity, it is not necessary to replace each target subtext in the source text separately to obtain all the transformed texts, but a part of the target subtext can be replaced according to the second quantity. For example, if the second quantity is M, in the case that the to-be-predicted text includes the source text, M-1 target subtexts can be replaced separately to obtain M-1 transformed texts. For example, if the second quantity is M, in the case that the to-be-predicted text does not include the source text, M target subtexts can be replaced separately to obtain M transformed texts.

[0093] In S230, each to-be-predicted text is processed by the same prediction model to obtain the probability of each predicted subtext item corresponding to each to-be-predicted text.

[0094] In the embodiments of the present disclosure, each to-be-predicted text can be input into the same prediction model, so as to obtain the output result of the prediction model, that is, the probability of each predicted subtext item corresponding to each to-be-predicted text under each candidate subtext.

[0095] Optionally, the prediction model can use an encoder-decoder model architecture based on a neural network such as Transformer, RNN or CNN, and the prediction model is a single model architecture different from ensemble learning.

[0096] In the embodiments of the present disclosure, since the same prediction model is used to process multiple to-be-predicted texts, the number of models is reduced, and the cost of model pre-training and model application deployment is reduced.

[0097] In some embodiments, the training method of the prediction model includes the following steps:

[0098] A sample data set is obtained, each sample data in the sample data set includes a sample transformed text corresponding to a sample source text and a sample target text corresponding to the sample source text.

[0099] The sample data set is used to train the neural network model to be trained to obtain the prediction model.

[0100] In the embodiments of the present disclosure, a plurality of sample source texts can be obtained first, and after obtaining the sample source texts, each sample source text can be processed, for example, a mask <mask>The target subtext in each sample source text is randomly replaced to construct a sample transformed text corresponding to each sample source text. In addition, the sample target text corresponding to the sample source text can be obtained by manual or traditional text generation model based on ensemble learning.

[0101] After the above processing, the sample transformed text corresponding to each sample source text and the sample target text corresponding to the sample source text can be obtained. Thus, the sample transformed texts corresponding to the plurality of sample source texts and the sample target texts corresponding to the sample source texts can be combined to form a sample data set, which is used to train the neural network model to be trained to obtain a prediction model.

[0102] In some embodiments, when the sample data set is used to train the neural network model to be trained, a negative log likelihood function NLL can be used as a model optimization target.

[0103] In the embodiments of the present disclosure, when the neural network model is trained, one target subtext in the sample source text is replaced to obtain the sample transformed text, so that the prediction model obtained by training has the ability to process the transformed text, thereby meeting the demand of processing different to-be-predicted texts.

[0104] S240, based on the sub-probabilities of the same candidate subtexts corresponding to the same prediction subtext item, obtaining the probabilities of the candidate subtexts corresponding to the same prediction subtext item.

[0105] S250, from the probabilities of the candidate subtexts corresponding to the same prediction subtext item, selecting the candidate subtext with the maximum probability as the information of the corresponding prediction subtext item.

[0106] S260, based on the information of each prediction subtext item, obtaining the target text corresponding to the source text.

[0107] In some embodiments, the probabilities of the candidate subtexts corresponding to the same prediction subtext item can be obtained by weighted average of the sub-probabilities of the same candidate subtexts corresponding to the same prediction subtext item.

[0108] In some embodiments, the weight coefficient corresponding to each to-be-predicted text can be set to 1.

[0109] In addition, considering that the sub-probabilities corresponding to the source text are relatively high in reliability, in some other embodiments, the weight coefficients of the sub-probabilities corresponding to the source text can be set to be relatively high, and the weight coefficients of the sub-probabilities corresponding to the transformed texts can be set to be relatively low, for example, the weight coefficient of the sub-probability corresponding to the source text is set to 5, and the weight coefficients of the sub-probabilities corresponding to the other transformed texts are all set to 4, so as to further improve the quality of the generated target text.

[0110] The processes of steps S240-S260 in the embodiments of the present disclosure will be exemplarily described below in combination with an example. In the example, the weight coefficients corresponding to each text to be predicted can all be set to 1.

[0111] It can be known in combination with the foregoing that, for the example of the source text being "today is Sunday", the probabilities of each sub-text item in the three predicted sub-text items t1, t2 and t3 of each text to be predicted being predicted as each candidate word in the word library can be obtained.

[0112] For example, it is assumed that, for the text to be predicted "today is Sunday", the sub-probability of being predicted as the candidate word "today" is 0.92 at the corresponding t1 position, the sub-probability of being predicted as the candidate word "yesterday" is 0.07, the sub-probability of being predicted as the candidate word "weather" is 0.01, and the sub-probabilities of being predicted as other candidate words are 0.

[0113] It is assumed that, for the text to be predicted "today is Sunday", the sub-probabilities of being predicted as the candidate words "today", "yesterday" and "weather" are 0.92, 0.07 and 0.01 respectively. <mask>"Sunday" at the corresponding t1 position, the sub-probability of predicting the candidate word "today" is 0.75, the sub-probability of predicting the candidate word "yesterday" is 0.18, the sub-probability of predicting the candidate word "weather" is 0.07, and the sub-probability of predicting other candidate words is 0.

[0114] Assuming that for the text to be predicted "today <mask>Sunday", at the corresponding t1 position, the sub-probability of predicting the candidate word "today" is 0.88, the sub-probability of predicting the candidate word "yesterday" is 0.07, the sub-probability of predicting the candidate word "weather" is 0.05, and the sub-probability of predicting other candidate words is 0.

[0115] At this time, the probabilities of each candidate word of the predicted sub-text item t1 can be predicted as follows: the probability of "today" is (0.92+0.75+0.88) / 3=0.85, the probability of "yesterday" is (0.07+0.18+0.07) / 3=0.107, and the probability of "weather" is (0.01+0.07+0.05) / 3=0.043.

[0116] At this time, the candidate word "today" with the maximum probability can be further obtained as the information corresponding to the predicted sub-text item t1. That is, "today" can be translated as "today".

[0117] Similarly, the probabilities of each candidate word of the predicted sub-text item t2 can be obtained, and the information corresponding to the predicted sub-text item t2, such as "is", can be obtained. The probabilities of each candidate word of the predicted sub-text item t3 can be obtained, and the information corresponding to the predicted sub-text item t3, such as "sunday", can be obtained.

[0118] Finally, after obtaining the information of each predicted sub-text item, the information of each predicted sub-text item can be combined in accordance with the order of each predicted sub-text item to obtain the target text corresponding to the source text, that is, the target text "today is sunday" is obtained.

[0119] In addition, in some embodiments, the maximum probability of each candidate text corresponding to each predicted sub-text item can also be obtained by the following formula:

[0120]

[0121] wherein M represents the number of texts to be predicted, t represents the tthpredicted sub-text item, x m represents the mthtext to be predicted, and θ represents a prediction model. represents the maximum probability of the candidate text corresponding to the tthpredicted sub-text item, y t represents the sub-probability of each candidate text corresponding to the tthpredicted sub-text item, and represents a negative log-likelihood function.

[0122] Figure 3 is a text generation apparatus block diagram according to an exemplary embodiment. Referring to the figure, the text generation apparatus 300 comprises an acquisition module 310, a determination module 320, a probability prediction module 330 and a target text generation module 340.

[0123] The acquisition module 310 is configured to acquire a transformed text corresponding to a source text;

[0124] The determination module 320 is configured to determine a plurality of to-be-predicted texts based on the source text and the transformed text;

[0125] The probability prediction module 330 is configured to perform prediction processing on each of the to-be-predicted texts by using a same prediction strategy, to obtain a probability of each predicted subtext item corresponding to each of the to-be-predicted texts, the probability of the predicted subtext item representing a sub-probability of the predicted subtext item being predicted as each candidate subtext in a text library;

[0126] The target text generation module 340 is configured to obtain a target text corresponding to the source text based on the probability of each predicted subtext item corresponding to each of the to-be-predicted texts.

[0127] In some embodiments, the acquisition module 310 comprises:

[0128] An acquisition sub-module configured to replace a target subtext in the source text with a preset text object to obtain the transformed text.

[0129] In some embodiments, the determination module 320 comprises:

[0130] A determination sub-module configured to determine a plurality of to-be-predicted texts from the source text and all transformed texts based on a number of target subtexts included in the source text, wherein the all transformed texts are obtained by respectively replacing all target subtexts in the source text with a preset text object.

[0131] In some embodiments, the determination sub-module comprises:

[0132] A first determination unit configured to determine the source text and all transformed texts as the to-be-predicted texts when the number of target subtexts included in the source text is less than or equal to a first number.

[0133] A second determination unit configured to select a second number of texts from a text set composed of the source text and all transformed texts as the to-be-predicted texts when the number of target subtexts included in the source text is greater than the first number.

[0134] In some embodiments, the target text generation module 340 comprises:

[0135] The probability determination sub-module is configured to determine the probability of each candidate subtext corresponding to the same predicted subtext item based on the sub-probabilities of the same candidate subtext corresponding to the same predicted subtext item.

[0136] The predicted subtext item information determination sub-module is configured to select the candidate subtext with the maximum probability as the information of the corresponding predicted subtext item from the probabilities of each candidate subtext corresponding to the same predicted subtext item.

[0137] The target text determination sub-module is configured to determine the target text corresponding to the source text based on the information of each predicted subtext item.

[0138] In some embodiments, the probability prediction module 330 includes:

[0139] The probability prediction sub-module is configured to respectively perform prediction processing on each of the to-be-predicted texts by the same prediction model to obtain the probability of each predicted subtext item corresponding to each to-be-predicted text under each candidate subtext.

[0140] In some embodiments, the apparatus 300 further includes:

[0141] The sample data set acquisition module is configured to acquire a sample data set, each sample data in the sample data set including a sample source text corresponding sample transformed text and a sample target text corresponding to the sample source text.

[0142] The training module is configured to train the to-be-trained neural network model by using the sample data set to obtain the prediction model.

[0143] As to the apparatus in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments of the method, and thus will not be described in detail here.

[0144] The present disclosure also provides a computer readable storage medium having stored thereon computer program instructions, which, when executed by a processor, implement the steps of the text generation method provided by the present disclosure.

[0145] Figure 4 is a block diagram of an electronic device 400 according to an exemplary embodiment. For example, the electronic device 400 can be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0146] Referring to Figure 4 The electronic device 400 can include one or more of the following components: a processing component 402, a memory 404, a power supply component 406, a multimedia component 408, an audio component 410, an input / output (I / O) interface 412, a sensor component 414, and a communication component 416.

[0147] The processing component 402 typically controls overall operations of the electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 402 can include one or more processors 420 to execute instructions to complete all or part of steps of the above methods. In addition, the processing component 402 can include one or more modules to facilitate

[0148] The memory 404 is configured to store various types of data to support operations of the electronic device 400. Examples of these data include instructions to operate any application programs or methods on the electronic device 400, contact data, phonebook data, messages, pictures, videos, and so on. The memory 404 can be implemented by any type of volatile or non-volatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic or optical disk.

[0149] The power supply component 406 supplies electrical power for the various components of the electronic device 400. The power supply component 406 can include a power supply management system, one or more power supplies, and other components associated with generating, managing and distributing electrical power for the electronic device 400.

[0150] The multimedia component 408 includes a screen to provide an output interface between the electronic device 400 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense a touch, a slide, or a gesture on the touch panel. The touch sensor can not only sense a boundary of a touching or a sliding action, but also detect duration and intensity of the touching or sliding action. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a camera mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have a focal length and optical zooming capability.

[0151] The audio component 410 is configured to output and / or input an audio signal. For example, the audio component 410 includes a microphone (MIC) to receive an external audio signal when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 404 or transmitted via the communication component 416. In some embodiments, the audio component 410 also includes a speaker to output an audio signal.

[0152] The input / output interface 412 provides an interface between the processing component 402 and peripheral interface modules, which can be a keypad, a click wheel, buttons, and the like. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.

[0153] The sensor component 414 includes one or more sensors to provide various state assessments for the electronic device 400. For example, the sensor component 414 can detect an open / closed state of the electronic device 400, relative positioning of components, such as a display and a keypad of the electronic device 400, a change in position of the electronic device 400 or a component of the electronic device 400, presence or absence of user contact with the electronic device 400, an orientation or acceleration / deceleration of the electronic device 400, and a temperature change of the electronic device 400. The sensor component 414 can include a proximity sensor to detect presence of an object within a proximity range of the electronic device 400 without any physical contact. The sensor component 414 can also include a light sensor, such as a CMOS or CCD image sensor, to use in an imaging application. In some embodiments, the sensor component 414 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0154] The communication component 416 is configured to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, 2G, or 3G, or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) techniques, infrared data association (IrDA) techniques, ultra-wideband (UWB) techniques, Bluetooth (BT) techniques, and other techniques.

[0155] In an exemplary embodiment, the electronic device 400 can be implemented with one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors, or other electronic elements, for performing the above-described methods.

[0156] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions, such as the memory 404 including instructions, is also provided, which can be executed by the processor 420 of the electronic device 400 to complete the above-described methods. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.

[0157] In another exemplary embodiment, a computer program product is also provided, which contains a computer program capable of being executed by a programmable device, and the computer program has code portions for executing the above-described text generation method when executed by the programmable device.

[0158] Other embodiments of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the present disclosure. It is intended that the present disclosure cover any and all variations of the present disclosure including those variations which can be incorporated into the above detailed description and making use of the general principles of the present disclosure. It is intended that the present disclosure include all such as fall within the scope of the appended claims and their equivalents. The specification and examples given are intended as illustrative only and not restrictive of the present disclosure. The true scope and spirit of the present disclosure is indicated by the appended claims.

[0159] It should be understood that the present disclosure is not limited to the precise construction that has been described above and shown in the accompanying drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope of the present disclosure. The scope of the present disclosure is indicated by the appended claims, rather than by the above description.< / mask> < / mask> < / mask> < / mask> < / mask> < / mask> < / mask> < / mask> < / mask>

Claims

1. A text generation method characterized by, The method comprises the following steps: obtaining a transformed text corresponding to a source text; determining a plurality of to-be-predicted texts based on the source text and the transformed text; performing prediction processing on each of the to-be-predicted texts by using a same prediction strategy to obtain a probability of each prediction subtext item corresponding to each of the to-be-predicted texts, the probability of the prediction subtext item representing a sub-probability of the prediction subtext item being predicted as each candidate subtext in a text library; performing weighted average on each sub-probability of a same candidate subtext corresponding to a same prediction subtext item to obtain a probability of each candidate subtext corresponding to the same prediction subtext item; selecting a candidate subtext with the maximum probability from the probabilities of each candidate subtext corresponding to the same prediction subtext item as information of the corresponding prediction subtext item; obtaining a target text corresponding to the source text based on the information of each prediction subtext item.

2. The method of claim 1, wherein, The method comprises the following steps: replacing a target subtext in the source text with a preset text object to obtain the transformed text.

3. The method of claim 1, wherein, The method comprises the following steps: determining the plurality of to-be-predicted texts from the source text and all transformed texts based on a number of target subtexts included in the source text, wherein the all transformed texts are obtained by replacing all target subtexts in the source text with the preset text object respectively.

4. The method of claim 3, wherein, The method comprises the following steps: when the number of target subtexts included in the source text is less than or equal to a first number, determining the source text and all transformed texts as the to-be-predicted texts; or when the number of target subtexts included in the source text is greater than the first number, selecting a second number of texts from a text set composed of the source text and all transformed texts as the to-be-predicted texts.

5. The method of claim 1, wherein, The method comprises the following steps: performing prediction processing on each of the to-be-predicted texts by using a same prediction model to obtain a probability of each prediction subtext item corresponding to each of the to-be-predicted texts.

6. The method of claim 5, wherein, The training method of the prediction model comprises the following steps: obtaining a sample data set, each sample data in the sample data set comprising a sample transformed text corresponding to a sample source text and a sample target text corresponding to the sample source text; training a neural network model to be trained by using the sample data set to obtain the prediction model.

7. A text generating apparatus characterized by comprising: The method comprises the following steps: an obtaining module configured to obtain a transformed text corresponding to a source text; a determining module configured to determine a plurality of to-be-predicted texts based on the source text and the transformed text; The probability prediction module is configured to perform prediction processing on each of the to-be-predicted texts through the same prediction strategy to obtain probabilities of each prediction subtext item corresponding to each of the to-be-predicted texts, the probability of the prediction subtext item representing a sub-probability of the prediction subtext item being predicted as each candidate subtext in the text library; The probability determination sub-module is configured to perform weighted average on each sub-probability of the same candidate subtext corresponding to the same prediction subtext item to obtain a probability of each candidate subtext corresponding to the same prediction subtext item; The prediction subtext item information determination sub-module is configured to select a candidate subtext with the largest probability from the probabilities of each candidate subtext corresponding to the same prediction subtext item as information of the corresponding prediction subtext item; The target text determination sub-module is configured to obtain a target text corresponding to the source text based on the information of each prediction subtext item.

8. An electronic device, comprising: The computer program is stored in the memory and includes the following steps: The processor is configured to execute the computer program in the memory to implement the steps of the method in any one of claims 1-6. The program instructions are executed by the processor to implement the steps of the method in any one of claims 1-6.

9. A computer-readable storage medium having stored thereon computer program instructions, wherein, ​

Citation Information

Patent Citations

  • Event generation method and device, terminal equipment and storage medium

    CN111460800A