A text generation method, device and storage medium
By receiving text generation instructions in the text generation device, obtaining text keywords and replacing target templates in the template library, the problem of lack of intelligence in text generation in the prior art is solved, and more efficient text generation is achieved.
Patent Information
- Application Number
- CN202111284961.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-01
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2041-11-01
AI Technical Summary
In the prior art, there is a lack of intelligence in generating text information, and manual search and association description templates are required, resulting in inefficiency.
By receiving text generation instructions, obtaining text keywords and determining their corresponding target text type, finding the target template in the template library, and replacing the field information of the target text type in the template to generate target text containing text keywords.
The intelligence of the text generation device when generating text information is improved, manual intervention is reduced, and efficiency is improved.
Smart Images

Figure CN114118041B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text generation method and device, and a storage medium. Background Art
[0002] With the development of Internet technology, the network pushes a lot of text information corresponding to objects to users every day, so that users can deeply understand the objects according to the text information and realize the processing process of the objects.
[0003] In the prior art, when descriptive information related to the object is obtained, a corresponding description template is manually searched, and the description template and the description information are manually associated to obtain corresponding text information, which reduces the intelligence when generating text information. Summary of the invention
[0004] In order to solve the above-mentioned technical problems, the embodiments of the present application hope to provide a text generation method and device, and a storage medium, which can improve the intelligence of the text generation device when generating text information.
[0005] The technical solution of this application is implemented as follows:
[0006] The present application provides a text generation method, including:
[0007] When receiving a text generation instruction, obtaining text keywords from the text generation instruction and determining a target text type corresponding to the text keywords;
[0008] In the case that a target template containing the target text type exists in the template library, acquiring the target template from the template library; the templates in the template library are text templates with text types set;
[0009] The position of the target text type is searched in the target template, and the field information corresponding to the target text type is replaced with the field information of the text keyword at the position to obtain the target text containing the text keyword.
[0010] The present application provides a text generation device, the device comprising:
[0011] an acquisition unit, configured to acquire text keywords from the text generation instruction when a text generation instruction is received; and to acquire the target template from the template library when a target template containing the target text type exists in the template library; the templates in the template library are text templates with text types set;
[0012] A determination unit, used to determine the target text type corresponding to the text keyword;
[0013] A replacement unit is used to replace the field information corresponding to the target text type with the field information of the text keyword at the position to obtain the target text containing the text keyword.
[0014] The present application provides a text generation device, the device comprising:
[0015] A memory, a processor and a communication bus, wherein the memory communicates with the processor via the communication bus, and the memory stores a text generation program executable by the processor. When the text generation program is executed, the above-mentioned text generation method is executed by the processor.
[0016] An embodiment of the present application provides a storage medium having a computer program stored thereon, which is applied to a text generation device, and is characterized in that the computer program implements the above-mentioned text generation method when executed by a processor.
[0017] The embodiment of the present application provides a text generation method and device, and a storage medium. The text generation method includes: when receiving a text generation instruction, obtaining text keywords from the text generation instruction, and determining the target text type corresponding to the text keywords; when there is a target template containing the target text type in the template library, obtaining the target template from the template library; the template in the template library is a text template with a text type; searching for the position of the target text type in the target template, and replacing the field information corresponding to the target text type with the field information of the text keywords at the position, thereby obtaining the target text containing the text keywords. The above method is implemented, and when the text generation device receives the text generation instruction, the text generation device obtains the text keywords from the text generation instruction, searches for the target template containing the target text type corresponding to the text keywords in the template library, and searches for the position of the target text type in the target template, and replaces the field information corresponding to the target text type with the field information of the text keywords at the position, thereby obtaining the target text containing the text keywords, and no longer needs to obtain the text information manually, thereby improving the intelligence of the text generation device when generating text information. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A flow chart of a text generation method provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of an exemplary BERT structure provided in an embodiment of the present application;
[0020] Figure 3 A schematic diagram of an exemplary supervised training BERT model provided in an embodiment of the present application;
[0021] Figure 4 A flowchart of an exemplary training BERT model provided in an embodiment of the present application;
[0022] Figure 5 An exemplary text template persistence flow chart provided for an embodiment of the present application;
[0023] Figure 6 A flowchart of an exemplary text generation method provided in an embodiment of the present application;
[0024] Figure 7 A schematic diagram of a seed phase and an automatic training phase of an exemplary text generation method provided in an embodiment of the present application;
[0025] Figure 8 A schematic diagram of the structure of a text generation device provided in an embodiment of the present application Figure 1 ;
[0026] Fig. 9 A schematic diagram of the structure of a text generation device provided in an embodiment of the present application Figure 2 . DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. It should be understood that the specific embodiments described here are only used to explain the present application and are not used to limit the present application.
[0028] Embodiment 1
[0029] The present application embodiment provides a text generation method, Figure 1 A text generation method process provided in the embodiment of the present application Figure 1 ,like Figure 1 As shown, the text generation method may include:
[0030] S101. When a text generation instruction is received, a text keyword is obtained from the text generation instruction, and a target text type corresponding to the text keyword is determined.
[0031] A text generation method provided in an embodiment of the present application is suitable for a scenario in which a target text is generated according to text keywords carried in a text generation instruction.
[0032] In the embodiments of the present application, the text generation device can be implemented in various forms. For example, the text generation device described in the present application can include devices such as mobile phones, cameras, tablet computers, laptop computers, PDAs, portable media players (PMPs), navigation devices, wearable devices, smart bracelets, pedometers, and devices such as digital TVs and desktop computers.
[0033] In an embodiment of the present application, the text generation instruction may be an instruction for generating a marketing text; the text generation instruction may also be an instruction for generating an advertising text; the text generation instruction may be an instruction for generating other texts; the specific text generation instruction may be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0034] In an embodiment of the present application, the text generation device may include a display screen, and the text generation device may receive text generation instructions from the display screen; the text generation device may also receive text generation instructions from other devices, and the text generation instructions may also be received in other ways; the specific way in which the text generation device receives the text generation instructions can be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0035] In the embodiment of the present application, the text keyword may be information used to generate a target text corresponding to the text generation instruction.
[0036] In the embodiment of the present application, the number of text keywords can be one, the number of text keywords can be two, or the number of text keywords can be multiple. The specific number of text keywords can be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0037] Exemplarily, the text keywords include bank, coupon, 10 yuan, January 1 to January 30, movie watching, card binding, etc.
[0038] In an embodiment of the present application, the number of target text types can be one, the number of target text types can be two, or the number of target text types can be multiple. The specific number of target text types can be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0039] Exemplarily, the target text type can be a company name; the target text type can also be a product name; the target text type can also be a distribution item; the target text type can also be a numerical amount; the target text type can also be an activity time or activity description; the specific target text type can be determined based on actual conditions, and the embodiments of the present application are not limited to this.
[0040] It should be noted that text keywords and target text types can be one-to-one corresponding, that is, one text keyword corresponds to one target text type; or two text keywords correspond to one target text type; or multiple text keywords correspond to one target text type; the specific correspondence between text keywords and target text types can be determined based on actual conditions, and the embodiments of the present application do not limit this.
[0041] In an embodiment of the present application, the process of a text generation device determining a target text type corresponding to a text keyword includes: when the target text type is not carried in the text generation instruction, the text generation device inputs the text keyword into a type recognition model to obtain the target text type; when the target text type is carried in the text generation instruction, the text generation device obtains the target text type from the text generation instruction.
[0042] It should be noted that the type recognition model can be a model configured in the text generation device; the type recognition model can also be a model obtained by the type recognition model from other devices before the text generation device inputs text keywords into the type recognition model; the type recognition model can also be a model obtained by the text generation device in other ways; the specific way in which the text generation device obtains the type recognition model can be determined according to actual conditions, and the embodiments of the present application are not limited to this.
[0043] In an embodiment of the present application, the type recognition model may be a text classification (FastText) model; the type recognition model may also be other models that can determine the text type based on text keywords; the specific type recognition model may be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0044] In an embodiment of the present application, the text generation device inputs text keywords into a type recognition model. Before obtaining the target text type, the text generation device also obtains second sample keywords and second sample text types; the text generation device uses the second sample keywords and the second sample text types to train an initial type recognition model to obtain a type recognition model.
[0045] In an embodiment of the present application, the second sample keyword may be a preset keyword; the second sample keyword may also be a keyword transmitted to the text generation device by other devices; the second sample keyword may also be a keyword received by the text generation device and obtained through manual annotation; the specific way in which the text generation device obtains the second sample keyword can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0046] In the embodiment of the present application, the second sample text type is a text type corresponding to the second sample keyword. The second sample text type can be a preset text type; the second sample text type can also be a text type transmitted to the text generation device by other devices; the second sample text type can also be a text type received by the text generation device and obtained by manual annotation; the specific way in which the text generation device obtains the second sample text type can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0047] In the embodiment of the present application, the text generation device may obtain the second sample keyword and the second sample text type only once.
[0048] Exemplarily, the second sample keywords include bank, coupon, 10 yuan, January 1 to January 30, movie watching, card binding, etc.
[0049] Exemplarily, the second sample text type includes: company name, product name, distributed items, numerical amount, activity time or activity description, etc.; the specific second sample text type can be determined according to actual conditions, and the embodiments of the present application are not limited to this.
[0050] S102: If there is a target template containing a target text type in the template library, obtain the target template from the template library; the template in the template library is a text template with a text type set.
[0051] In an embodiment of the present application, after the text generating device determines the target text type corresponding to the text keyword, if there is a target template containing the target text type in the template library, the text generating device obtains the target template from the template library.
[0052] It should be noted that the templates in the template library are text templates with text types set.
[0053] In an embodiment of the present application, the number of text templates can be one, or the number of text templates can be two; the number of text templates can also be multiple, and the specific number of text templates can be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0054] In an embodiment of the present application, before the text generation device obtains the target template from the template library, the text generation device also obtains a first sample text; and inputs the first sample text into a keyword recognition model to obtain a first sample keyword, a first sample type, and a first position of the first sample keyword in the first sample text corresponding to the first sample text; the text generation device inputs the first sample keyword into the text generation model to obtain a first output text; obtains a text template based on the first output text, the first sample text, the first sample keyword, the first sample type, and the first position, and adds the text template to the template library.
[0055] In an embodiment of the present application, the text generation device may obtain the first sample text at preset time intervals; the text generation device may also obtain the first sample text upon receiving a sample text acquisition instruction; the text generation device may also obtain the first sample text in other ways; the specific way in which the text generation device obtains the first sample text can be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0056] It should be noted that the preset time period can be a time period configured in the text generating device; the preset time period can also be a time period received by the text generating device before the text generating device obtains the first sample text; the preset time period can also be a time period obtained by the text generating device in other ways. The specific way in which the text generating device obtains the preset time period can be determined according to actual conditions, and the embodiments of the present application are not limited to this.
[0057] It should also be noted that the preset time period can be one week; the preset time period can also be one month; the preset time period can also be one day; the specific preset time period can be determined according to actual conditions, and the embodiments of the present application do not limit this.
[0058] In the embodiments of the present application, the keyword recognition model may be a model configured in the text generation device; the keyword recognition model may also be a model transmitted by other devices and received by the text generation device; the keyword recognition model may also be a model acquired by the text generation device in other ways; the specific way in which the text generation device acquires the keyword recognition model may be determined based on actual conditions, and the embodiments of the present application do not limit this.
[0059] In an embodiment of the present application, the keyword recognition model can be a model obtained by a language representation model (Bidirectional Encoder Representation from Transformers, BERT) and a conditional random field model; the keyword recognition model can also be other models that can obtain the sample keywords, sample types and positions of the sample keywords in the sample text corresponding to the sample text based on the sample text; the specific keyword recognition model can be determined according to actual conditions, and the embodiment of the present application is not limited to this.
[0060] In the embodiments of the present application, the text generation model may be a model configured in the text generation device; the text generation model may also be a model transmitted by other devices and received by the text generation device; the text generation model may also be a model acquired by the text generation device in other ways; the specific way in which the text generation device acquires the text generation model may be determined based on actual conditions, and the embodiments of the present application do not limit this.
[0061] In an embodiment of the present application, the text generation model may be a Fixed-Keywords BERT model; the text generation model may also be other models that can generate output text based on text keywords; the specific text generation model may be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0062] In an embodiment of the present application, a process in which a text generating device obtains a text template based on a first output text, a first sample text, a first sample keyword, a first sample type and a first position includes: the text generating device uses a keyword recognition model to determine the second position of the first sample keyword in the first output text; the text generating device replaces the first sample keyword with the first sample type at the second position in the first output text to obtain a first template; the text generating device replaces the first sample keyword with the first sample type at the first position in the first sample text to obtain a second template; the text generating device uses the first template and the second template as text templates.
[0063] In an embodiment of the present application, the text generation device uses a keyword recognition model to determine the second position of the first sample keyword in the first output text. The text generation device can input the first output text into the keyword recognition model, and use the keyword recognition model to determine the second position of the first sample keyword in the first output text.
[0064] In an embodiment of the present application, the first template and the second template may be the same; the first template and the second template may also be different; if the number of first templates and the number of second templates are both multiple, then the first template and the second template may also have some identical templates and some different templates; the specific number may be determined based on actual conditions, and the embodiment of the present application is not limited to this.
[0065] It should be noted that the first position and the second position may be the same; the first position and the second position may also be different; the specific position may be determined according to actual conditions, and the embodiments of the present application do not limit this.
[0066] In an embodiment of the present application, the text generation device inputs the first sample text into the keyword recognition model to obtain the first sample keyword, the first sample type and the first position of the first sample keyword corresponding to the first sample text. Before the text generation device also obtains the second sample text and the second sample keyword corresponding to the second sample text, the second sample type and the second sample keyword corresponding to the second sample text in the third position of the second sample text; the text generation device uses the second sample keyword, the second sample type, the third position and the second sample text to train the initial keyword recognition model to obtain the keyword recognition model.
[0067] In the embodiment of the present application, the text generation device is configured with a regular expression of a combination of {marketing words} and {product / company name}. The text generation device can use the regular expression to obtain the second sample text from the entire Internet data, and annotate the second sample text with the corresponding second sample keywords, second sample types, and the third position of the second sample keywords in the second sample text by manual annotation. Then, the second sample keywords, second sample types, and third positions are transmitted to the text generation device, and the text generation device obtains the second sample keywords, second sample types, and third positions.
[0068] In the embodiment of the present application, marketing words are words related to financial marketing, and are configured in the text generation device. The marketing words include: receive, welfare, discount, red envelope, limited time, special price, free shipping, recharge, coupon, membership, cash, heavyweight, good news, exclusive, exclusive, value for money, special offer, gift, feedback, exchange, activation, send, subsidy, 11.11, 12.12, Double Eleven, Double Twelve, lottery, Double 11, Double 12, considerate, save money, discount, boutique, free shipping, warm winter, exquisite, waiting for you get, flash sale, free, coupon, discount, give, gift, present, store anniversary, limited to, discount, exchange, good news, surprise, carnival, shocking, launch, event, special price, special, special offer, incoming, bargain, direct reduction, save money, subsidy, instant reduction, red envelope, limited time, points, online, shocking, hurry up, [low less, let go, reduction].*[interest rate, interest price], [interest rate, interest price].*[low less, let go, reduction], full.* reduction, exclusive, unsecured, come and grab, come quickly, quickly, must-have, recharge, rebate, opening, latest.
[0069] In the embodiment of the present application, the product / company name is a financial-related product and a company name or abbreviation, which is represented by "{product / company name}".
[0070] Exemplarily, the regular expression combining {marketing word} and {product / company name} may be: {marketing word}.*{product / company name}; the regular expression combining {marketing word} and {product / company name} may also be {product / company name}.*{marketing word}.
[0071] It should be noted that the first sample text may also be sample text information obtained from all Internet data at preset time intervals using the regular expression.
[0072] In an embodiment of the present application, if the second sample keyword is bank, the corresponding second sample type is company name; if the second sample keyword is coupon, the corresponding second sample type is distributed item; if the second sample keyword is 10 yuan, the corresponding second sample type is amount value; if the second sample keyword is January 1 to January 30, the corresponding second sample type is activity time.
[0073] For example, if the second sample text is "The company is giving out benefits! A 50 yuan red envelope, come and claim it", then the corresponding first second sample keyword is company, the corresponding first second sample type is company name, and the corresponding first third position is (0, 2); the corresponding second second sample keyword is 50 yuan, the corresponding second second sample type is the amount, and the corresponding second third position is (7, 10); the corresponding third second sample keyword is red envelope, the corresponding third second sample type is distributed items, and the corresponding third third position is (10, 12).
[0074] It should be noted that the third position may be a pair of start and end positions where the second sample keyword appears in the second sample text.
[0075] In an embodiment of the present application, after the text generation device determines the target text type corresponding to the text keyword, the text generation device determines at least two empty positions formed according to the text keyword and at least two groups of character quantities corresponding to the at least two empty positions when the target template of the target text type is not included in the template library; the text generation device splices the at least two empty positions and the keyword according to the at least two groups of character quantities to obtain splicing information; the text generation device inputs the splicing information into the text generation model to obtain at least two groups of target character information corresponding to the at least two empty positions; the text generation device adds at least two groups of target character information at the at least two empty positions in the splicing information to obtain the target text.
[0076] It should be noted that at least two empty positions correspond to at least two groups of character quantities in a one-to-one manner, that is, at least one empty position corresponds to a group of character quantities.
[0077] It should be noted that, when the number of text keywords is one, there will be an empty position on the left of the text keyword, and a second empty position on the right of the text keyword; when the number of text keywords is two, there will be an empty position on the left of the first text keyword, a second empty position between the first and second text keywords; a third empty position on the right of the second text keyword; ...; when the number of text keywords is N, there will be an empty position on the left of the first text keyword, a second empty position between the first and second text keywords; ...; there will be an N-th empty position between the N-1th text keyword and the Nth text keyword; there will be an N+1th empty position on the right of the Nth text keyword. That is, when the number of text keywords is N, the corresponding number of empty positions is N+1.
[0078] In an embodiment of the present application, a text generation device inputs splicing information into a text generation model to obtain at least two groups of target character information corresponding to at least two empty positions, including the text generation device inputting the splicing information into the text generation model, using the text generation model to obtain the first word in each group of at least two empty positions by sampling, that is, obtaining at least two groups of first words; then inputting the at least two groups of first words and the splicing information into the text generation model, using the text generation model to obtain at least two groups of second words in at least two empty positions by sampling, until each word in at least two empty positions is obtained by sampling using the text generation model, that is, obtaining at least two groups of target character information.
[0079] It should be noted that the structure of BERT Figure 2 As shown in the figure: BERT can be divided into three parts: word vector conversion part, encoding part and supervision part. Among them, when receiving the input text, the word vector conversion part is first used to convert the input text into a word vector to obtain a word vector sequence (CLS, word 1, word 2, word 3, ..., word N), and then the word vector sequence is encoded by the encoding part of BERT, and finally the text category of the encoded input text is determined by the supervision part. The encoding part is the main body of BERT, and its main function is to encode the input N+1 word vectors so that information interaction occurs between all input vectors. The encoding part consists of several layers of encoding blocks. The first encoding block in the encoding part can obtain the first encoding sequence (E CLS , E1, E2, E3, …, E n )(The first coding sequence is Figure 3 The encoding block in the encoding part encodes the word vector sequence to obtain the encoding output sequence (E CLS , E1, E2, E3, …, E n )(The encoded output sequence is Figure 3 Finally, the supervision part includes the labels corresponding to the input text required to complete the supervised training of BERT. Figure 3 The example in Figure 1 shows the multi-category classification of the input text. At this point, you only need to take the encoded output sequence output by the encoding part and map the encoded output sequence to the target category (text category) to start supervised training. The supervision part can be adjusted according to the task objectives, such as named entity recognition, question answering, etc.
[0080] In an embodiment of the present application, if the text generation model is a Fixed-Keywords BERT model, the function of the text generation model is to generate marketing copy (ie, target text) containing these template keywords based on given template keywords.
[0081] In the embodiments of the present application, Figure 3 The supervised training process of generating the marketing copy (output text) "Come and get the bank red envelope!" by inputting "bank" and "red envelope" as sample keywords is shown. First, the word vectors of "bank", "red envelope" and the mask part are converted to obtain a word vector sequence; the word vector sequence is encoded using the first encoding block in the encoding part to obtain the first encoding sequence (E CLS 、E M 、E M 、E M 、E 银 、E 行 、EM 、E M 、E M 、E 红 、E 包 、E M 、E M 、E M ), until the last coding block in the coding part is used to encode the coded output sequence, and the coded output part is supervised by the supervision part to obtain the prediction result (come and get it, ---, la! -).
[0082] Specifically: Since the input only contains the two words "bank" and "red envelope", they cannot form a complete marketing copy. However, the spaces formed by these two words in order (to the left of "bank", between "bank" and "red envelope", to the right of "red envelope") may contain words that form this marketing copy. At this time, we need to first set the maximum number of words that appear in these spaces, L M .L M There are two ways to set it:
[0083] The first method is to determine the number of characters corresponding to the empty space value formed by the sample keywords in the sample text based on the sample text and the sample keywords. For example, for the marketing copy "Come and get the bank red envelope!" and the sample keywords it contains:
[0084] Sample type: <Company name>, Sample keyword: Bank, Keyword position: (3, 5)
[0085] Sample type: <distribute items>, sample keyword: red envelope, keyword position: (5, 7)
[0086] It can be determined that the number of words contained in the three empty spaces are: 3, 0, and 2 respectively.
[0087] The second is: take the maximum value of the number of words corresponding to all vacant values, which can be L M Then, use L M A mask vector (denoted as M) is inserted into the spaces between all sample keywords. For example, for the input "bank" and "red envelope", L can be inserted before "bank", between "bank" and "red envelope", and after "red envelope". M mask vector. Figure 3 As shown, assuming L M The value is 3, and the word vector conversion part shows the final result including the mask.
[0088] It can be understood that, with the maximum value as the number of characters corresponding to the empty position value, there will be sufficient positions (most sufficient mask parts) to predict the target character at the empty position, thereby improving the accuracy of predicting the target character information.
[0089] In the embodiment of the present application, in the supervision part, the mask part is supervised. If the number of words in the corresponding position in the sample copy is less than L M , supervision starts from the leftmost part of the mask, and the supervision object of the remaining positions is "-", such as Figure 3 In the figure, "---" indicates that there is no word here. When the predicted target character corresponding to the mask part is predicted, the final marketing copy can be obtained by removing the "-" in the predicted target character and the sample keyword.
[0090] For example, the process of training a text generation model is as follows: Figure 4 As shown:
[0091] S41. The text generating device obtains a second sample text and a second sample keyword corresponding to the second sample text.
[0092] S42. The text generation device constructs a word vector sequence using the second sample keyword.
[0093] For example, for the marketing copy (second sample text) "Come and get the bank red envelope!", and the second sample keywords contained therein:
[0094] Second sample type: <Company name>, second sample keyword: Bank, third position: (3, 5)
[0095] Second sample type: <distribute items>, second sample keyword: red envelope, third position: (5, 7)
[0096] First, the second sample keywords are converted into word vectors from left to right according to their positions in the marketing copy, and each word is directly converted into a 200-dimensional vector. All word vectors of the two words are concatenated together to construct a 200-dimensional word vector sequence with a length of 4. Then, all vacancies formed by the two second sample keywords are filled with mask vectors.
[0097] For example, if the number of characters in each mask part is L M If is 3, then for each vacancy, three 200-dimensional mask vectors are inserted, all initialized to all 0 vectors. After insertion, a 200-dimensional vector sequence with a length of 3 (mask vector sequence length) + 2 ("bank" vector sequence length) + 3 (mask vector sequence length) + 2 ("red envelope" vector sequence length) + 3 (mask vector sequence length) can be obtained. At this point, the word vector conversion part of the Fixed-Keywords BERT model is completed, and the word vector sequence is obtained.
[0098] S43: The text generating device constructs a training label according to the second sample text.
[0099] In the embodiments of the present application, the training label represents the result expected to be obtained after inputting data into the model, that is, the real marketing copywriting. When constructing the word vector sequence, a mask is inserted at each empty position, and it is necessary to ensure that the training label corresponds to the word vector sequence at each word position.
[0100] Exemplarily, a vector sequence can be constructed: [M, M, M, bank, M, M, M, red, packet, M, M, M]. Then, its corresponding training label is constructed as follows: [Hurry, come, get, bank, -, -, -, red, packet, now, !, -]. Here, "-" indicates no character at the corresponding position.
[0101] S44. The text generation device inputs the word vector sequence into the encoding part of the initial text generation model to obtain an encoded output sequence.
[0102] S45. The text generation device trains the initial text generation model according to the encoded output sequence and the training label to obtain the text generation model.
[0103] It should be noted that after the text generation device obtains the encoded output sequence, the text generation device maps each vector (except the CLS vector) in the encoded output sequence to the word table set (including "-").
[0104] Exemplarily, after inputting the word vector sequence [M, M, M, bank, M, M, M, red, packet, M, M, M] into the encoding part of the initial text generation model, an encoded output sequence of 200-dimensional vector sequence with a length of 13 is obtained. For each vector, multiply it by a trainable matrix (the shape of the matrix is: 200×(word table size + 1), 1 represents "-") to map the vector to the target word table (including "-"). Then, the cross-entropy between the mapped vector sequence and the training label: [Hurry, come, get, bank, -, -, -, red, packet, now, !, -] can be determined, and the parameters of the initial text generation model can be fine-tuned and updated by means of gradient descent, etc. When the initial text generation model converges (that is, the parameters of the initial text generation model cannot be updated) or reaches the maximum number of training steps, it can be considered that the initial text generation model has been trained, and thus the text generation model is obtained.
[0105] In the embodiment of the present application, after model training, the Fixed-Keywords BERT model will acquire the following capabilities: input the two words "bank" and "red envelope", output "Come and get it" on the left side of "bank", "---" between "bank" and "red envelope", and "la!-" on the right side of "red envelope". Among them, "-" means that there is no character here. The mask part after removing the "-" is spliced together with "bank" and "red envelope" in sequence to obtain the complete marketing copy: "Come and get the bank red envelope!". Since "bank" and "red envelope" are sample keywords, each has its corresponding sample type. Therefore, the sample keywords in the generated marketing copy can be further replaced with the corresponding sample types, that is, "<company name>" is used to replace "bank", and "<distributed items>" is used to replace "red envelope". The template can be obtained: "Come and get <company name> <distributed items>!". The persistence of the template is completed. Specifically, the flowchart for persistence as a text template is as follows. Figure 5 As shown:
[0106] S51. The text generating device obtains a first sample keyword.
[0107] In the embodiment of the present application, the text generation device obtains the first sample keyword and the first sample type corresponding to the first sample keyword at the same time. Specifically, the text generation device can input the first sample text into the keyword recognition model to obtain the first sample keyword and the first sample type corresponding to the first sample text.
[0108] In the embodiment of the present application, the text generation device also needs a first sample keyword sequence. Exemplarily, the input first sample keyword can be in the form of:
[0109] First sample type: <Company name>, first sample keyword: Bank;
[0110] The first sample type: <distributed items>, the first sample keyword: interest-free coupon
[0111] It should be noted that the input first sample keyword sequence is order-sensitive, that is, the order of the input first sample keyword sequence is consistent with the order in which it appears in the final generated marketing copy. In order to generate a text template later, it is necessary to obtain the first sample type.
[0112] S52: The text generation device inputs the first sample keyword into the text generation model to obtain a first output text.
[0113] In the embodiment of the present application, the maximum number of words L that appear in the spaces formed by the two words bank and interest-free coupon in order (the left side of "bank", between "bank" and "interest-free coupon", and the right side of "interest-free coupon") is M If L Mis 3, the constructed sequence of word vectors can be:
M, M, M, bank, coupon, M, M, M, interest-free, coupon, M, M, M
[0114] Exemplarily, corresponding to the sequence of word vectors:
M, M, M, bank, coupon, M, M, M, interest-free, coupon, M, M, M
-, -, -, bank, large-amount, -, interest-free, coupon, enjoy, non-stop
[0115] It should be noted that by removing the "-" indicating the non-existence of characters here, the predicted marketing copy (the first output text) can be obtained: "Enjoy large-amount interest-free coupons from the bank without stopping".
[0116] S53. The text generation device uses the keyword recognition model to determine the second position of the first sample keyword in the first output text.
[0117] S54. The text generation device uses the first sample type to replace the first sample keyword at the second position in the first output text to obtain the first template; and use the first template as the text template.
[0118] In the embodiment of the present application, replace the first sample keyword in the predicted marketing copy: "Enjoy large-amount interest-free coupons from the bank without stopping" with the corresponding first sample type, that is, replace "bank" with the first sample type "<company name>", and replace "interest-free coupon" with the first sample type "<issued item>", the final first template can be obtained: "<company name> large <issued item> enjoy non-stop", and store the first template, that is, complete the persistence of the marketing copy template.
[0119] S103. Search for the position of the target text type in the target template, and replace the field information corresponding to the target text type with the field information of the text keyword at the position to obtain the target text containing the text keyword.
[0120] In an embodiment of the present application, after the text generation device searches for a target template containing a target text type in a template library, the text generation device can then search for the position of the target text type in the target template, and replace the field information corresponding to the target text type with the field information of the text keywords at the position to obtain a target text containing the text keywords.
[0121] It should be noted that the target text is the text corresponding to the text generation instruction.
[0122] Exemplarily, a schematic diagram of an exemplary text generation method is as follows Figure 6 As shown:
[0123] S61. When receiving a text generation instruction, the text generation device obtains text keywords from the text generation instruction.
[0124] S62: When the target text type is not carried in the text generation instruction, the text generation device inputs the text keywords into the type recognition model to obtain the target text type.
[0125] S63: When the text generation instruction carries the target text type, the text generation device obtains the target text type from the text generation instruction.
[0126] S64: When there is a target template containing the target text type in the template library, the text generating device obtains the target template from the template library.
[0127] S65. The text generating device searches for the position of the target text type in the target template, and replaces the field information corresponding to the target text type with the field information of the text keyword at the position to obtain the target text containing the text keyword.
[0128] S66. When the template library does not contain a target template of the target text type, the text generating device determines at least two empty positions formed according to text keywords and at least two groups of character quantities corresponding to the at least two empty positions.
[0129] S67. The text generating device splices at least two empty positions and the keyword according to at least two groups of character quantities to obtain splicing information.
[0130] S68. The text generation device inputs the splicing information into a text generation model to obtain at least two groups of target character information corresponding to at least two empty positions.
[0131] S69. The text generating device adds at least two groups of target character information at at least two empty positions in the splicing information to obtain a target text.
[0132] Exemplarily, an exemplary text generation method includes a seed phase and an automatic training phase, such as Figure 7 As shown. Among them, the seed stage is to first obtain the second sample text, and manually annotate the second sample text to obtain the second sample keyword corresponding to the second sample text, the second sample type corresponding to the second sample text, and the third position of the second sample keyword in the second sample text; use the second sample keyword, the second sample type, the third position, and the second sample text to train the initial keyword recognition model to obtain a keyword recognition model (training keyword recognition model). Use the second sample keyword and the second sample text type to train the initial type recognition model to obtain a type recognition model (training type recognition model). The automatic training stage is to obtain a first sample text, and input the first sample text into a keyword recognition model to obtain a first sample keyword, a first sample type and a first position of the first sample keyword in the first sample text corresponding to the first sample text (the first sample text is annotated using the keyword recognition model); input the first sample keyword into a text generation model to obtain a first output text; use the keyword recognition model to determine the second position of the first sample keyword in the first output text; at the second position in the first output text, replace the first sample keyword with the first sample type to obtain a first template; at the first position in the first sample text, replace the first sample keyword with the first sample type to obtain a second template; use the first template and the second template as text templates (to obtain a text template), and add the text template to a template library so that when a text generation instruction is received, a target text containing the text keyword is obtained according to the text keyword in the text generation instruction and the target template in the template library.
[0133] It can be understood that when the text generation device receives a text generation instruction, it obtains text keywords from the text generation instruction, searches for a target template that includes a target text type corresponding to the text keywords in the template library, and searches for the position of the target text type in the target template, so as to replace the field information corresponding to the target text type at that position with the field information of the text keywords, thereby obtaining a target text containing the text keywords. There is no need to obtain the text information manually, which improves the intelligence of the text generation device when generating text information.
[0134] Embodiment 2
[0135] Based on the same inventive concept of the first embodiment, the present application embodiment provides a text generation device 1, corresponding to a text generation method; Figure 8 A schematic diagram of the structure of a text generation device provided in an embodiment of the present application Figure 1 , the text generation device 1 may include:
[0136] The acquisition unit 11 is used to acquire text keywords from the text generation instruction when receiving the text generation instruction; if there is a target template containing the target text type in the template library, acquire the target template from the template library; the template in the template library is a text template with a text type set;
[0137] A determination unit 12, used to determine the target text type corresponding to the text keyword;
[0138] The replacement unit 13 is used to replace the field information corresponding to the target text type with the field information of the text keyword at the position to obtain the target text containing the text keyword.
[0139] In some embodiments of the present application, the device further includes an input unit and an adding unit;
[0140] The acquisition unit 11 is used to acquire a first sample text;
[0141] The input unit is used to input the first sample text into a keyword recognition model to obtain a first sample keyword, a first sample type and a first position of the first sample keyword in the first sample text corresponding to the first sample text; input the first sample keyword into a text generation model to obtain a first output text; and obtain the text template according to the first output text, the first sample text, the first sample keyword, the first sample type and the first position;
[0142] The adding unit is used to add the text template to the template library.
[0143] In some embodiments of the present application, the determining unit 12 is used to determine a second position of the first sample keyword in the first output text using a keyword recognition model;
[0144] The replacement unit 13 is used to replace the first sample keyword with the first sample type at the second position in the first output text to obtain a first template; replace the first sample keyword with the first sample type at the first position in the first sample text to obtain a second template; and use the first template and the second template as the text template.
[0145] In some embodiments of the present application, the apparatus further comprises a training unit;
[0146] The acquiring unit 11 is used to acquire a second sample text and a second sample keyword corresponding to the second sample text, a second sample type corresponding to the second sample text and a third position of the second sample keyword in the second sample text;
[0147] The training unit is used to train an initial keyword recognition model using the second sample keyword, the second sample type, the third position and the second sample text to obtain the keyword recognition model.
[0148] In some embodiments of the present application, the device further comprises a splicing unit;
[0149] The determining unit 12 is used to determine at least two empty positions formed according to the text keywords and at least two groups of character quantities corresponding to the at least two empty positions when the template library does not contain the target template of the target text type; the at least two empty positions correspond to the at least two groups of character quantities in a one-to-one manner;
[0150] The splicing unit is used to splice the at least two empty positions and the keyword according to the at least two groups of character quantities to obtain splicing information;
[0151] The input unit is used to input the splicing information into a text generation model to obtain at least two groups of target character information corresponding to the at least two empty positions;
[0152] The adding unit is used to add the at least two groups of target character information at the at least two empty positions in the splicing information to obtain the target text.
[0153] In some embodiments of the present application, the input unit is used to input the text keywords into a type recognition model to obtain the target text type when the target text type is not carried in the text generation instruction;
[0154] The acquisition unit 11 is used to acquire the target text type from the text generation instruction when the text generation instruction carries the target text type.
[0155] In some embodiments of the present application, the acquisition unit 11 is used to acquire a second sample keyword and a second sample text type;
[0156] The training unit is used to train an initial type recognition model using the second sample keywords and the second sample text type to obtain the type recognition model.
[0157] It should be noted that, in actual applications, the above-mentioned acquisition unit 11, determination unit 12 and replacement unit 13 can be implemented by a processor 14 on the text generation device 1, specifically a CPU (Central Processing Unit), an MPU (Microprocessor Unit), a DSP (Digital Signal Processing) or a field programmable gate array (FPGA); the above-mentioned data storage can be implemented by a memory 15 on the text generation device 1.
[0158] The present application embodiment also provides a text generation device 1, such as Fig. 9 As shown, the text generation device 1 includes: a processor 14, a memory 15 and a communication bus 16. The memory 15 communicates with the processor 14 via the communication bus 16. The memory 15 stores a program executable by the processor 14. When the program is executed, the text generation method described above is executed by the processor 14.
[0159] In practical applications, the memory 15 may be a volatile memory, such as a random access memory (RAM); or a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD); or a combination of the above types of memory, and provide instructions and data to the processor 14.
[0160] An embodiment of the present application provides a computer-readable storage medium having a computer program thereon, and when the program is executed by the processor 14, the text generation method as described above is implemented.
[0161] It can be understood that when the text generation device receives a text generation instruction, it obtains text keywords from the text generation instruction, searches for a target template that includes a target text type corresponding to the text keywords in the template library, and searches for the position of the target text type in the target template, so as to replace the field information corresponding to the target text type at that position with the field information of the text keywords, thereby obtaining a target text containing the text keywords. There is no need to obtain the text information manually, which improves the intelligence of the text generation device when generating text information.
[0162] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of hardware embodiments, software embodiments, or embodiments in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) that contain computer-usable program code.
[0163] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0166] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application.
Claims
1. A text generation method, characterized in that: The method comprises: When receiving a text generation instruction, obtaining text keywords from the text generation instruction and determining a target text type corresponding to the text keywords; In the case that a target template containing the target text type exists in the template library, acquiring the target template from the template library; the templates in the template library are text templates with text types set; Searching for the position of the target text type in the target template, and replacing the field information corresponding to the target text type with the field information of the text keyword at the position to obtain a target text containing the text keyword; In the case that the template library does not contain a target template of the target text type, determining at least two empty positions formed according to the text keywords and at least two groups of character quantities corresponding to the at least two empty positions; the at least two empty positions correspond to the at least two groups of character quantities in a one-to-one manner; splicing the at least two empty positions and the text keyword according to the at least two groups of character quantities to obtain splicing information; Inputting the splicing information into a text generation model to obtain at least two groups of target character information corresponding to the at least two empty positions; The at least two groups of target character information are added to the at least two empty positions in the splicing information to obtain a target text containing the text keyword.
2. The method according to claim 1, characterized in that Before acquiring the target template from the template library, the method further includes: Obtain a first sample text; and input the first sample text into a keyword recognition model to obtain a first sample keyword, a first sample type, and a first position of the first sample keyword in the first sample text corresponding to the first sample text; Inputting the first sample keyword into a text generation model to obtain a first output text; The text template is obtained according to the first output text, the first sample text, the first sample keyword, the first sample type and the first position, and the text template is added to the template library.
3. The method according to claim 2, characterized in that The obtaining the text template according to the first output text, the first sample text, the first sample keyword, the first sample type and the first position includes: Determine a second position of the first sample keyword in the first output text using a keyword recognition model; At the second position in the first output text, replacing the first sample keyword with the first sample type to obtain a first template; At the first position in the first sample text, the first sample keyword is replaced with the first sample type to obtain a second template; The first template and the second template are used as the text templates.
4. The method according to claim 2, characterized in that: The method further comprises: inputting the first sample text into a keyword recognition model to obtain a first sample keyword, a first sample type, and the first sample keyword before a first position in the first sample text corresponding to the first sample text. Acquire a second sample text and a second sample keyword corresponding to the second sample text, a second sample type corresponding to the second sample text, and a third position of the second sample keyword in the second sample text; The initial keyword recognition model is trained using the second sample keyword, the second sample type, the third position and the second sample text to obtain the keyword recognition model.
5. The method according to claim 1, characterized in that The determining of the target text type corresponding to the text keyword includes: In the case where the target text type is not carried in the text generation instruction, inputting the text keywords into a type recognition model to obtain the target text type; In a case where the target text type is carried in the text generation instruction, the target text type is obtained from the text generation instruction.
6. The method according to claim 5, characterized in that Before inputting the text keywords into a type recognition model to obtain the target text type, the method further includes: Obtain a second sample keyword and a second sample text type; The initial type recognition model is trained using the second sample keyword and the second sample text type to obtain the type recognition model.
7. A text generation device, characterized in that: The device comprises: an acquisition unit, configured to, upon receiving a text generation instruction, acquire a text keyword from the text generation instruction and determine a target text type corresponding to the text keyword; and acquire the target template from the template library if a target template containing the target text type exists in the template library; the templates in the template library are text templates with text types set; A replacement unit, used for searching the position of the target text type in the target template, and replacing the field information corresponding to the target text type with the field information of the text keyword at the position to obtain a target text containing the text keyword; a determining unit, configured to determine, when the template library does not contain the target template of the target text type, at least two empty positions formed according to the text keywords and at least two groups of character quantities corresponding to the at least two empty positions; the at least two empty positions correspond to the at least two groups of character quantities in a one-to-one manner; A splicing unit, configured to splice the at least two empty positions and the text keyword according to the at least two groups of character quantities to obtain splicing information; An input unit, used for inputting the splicing information into a text generation model to obtain at least two groups of target character information corresponding to the at least two empty positions; The adding unit is used to add the at least two groups of target character information at the at least two empty positions in the splicing information to obtain the target text containing the text keyword.
8. A text generation device, characterized in that: The device comprises: A memory, a processor and a communication bus, wherein the memory communicates with the processor via the communication bus, the memory stores a text generation program executable by the processor, and when the text generation program is executed, the method according to any one of claims 1 to 6 is performed by the processor.
9. A storage medium having a computer program stored thereon, applied to a text generation device, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method, apparatus, storage medium and terminal device for generating short text
CN108959256A
Template generation method and device, electronic equipment and computer readable medium
CN110059163A