CN109002433B - Text generation method and device - Google Patents

Text generation method and device Download PDF

Info

Publication number
CN109002433B
CN109002433B CN201810540691.2A CN201810540691A CN109002433B CN 109002433 B CN109002433 B CN 109002433B CN 201810540691 A CN201810540691 A CN 201810540691A CN 109002433 B CN109002433 B CN 109002433B
Authority
CN
China
Prior art keywords
sentence
character sequence
ith
character
text
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810540691.2A
Other languages
Chinese (zh)
Other versions
CN109002433A (en
Inventor
祝文博
李超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Mobvoi Innovation Technology Co Ltd
Original Assignee
Mobvoi Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Mobvoi Information Technology Co Ltd filed Critical Mobvoi Information Technology Co Ltd
Priority to CN201810540691.2A priority Critical patent/CN109002433B/en
Publication of CN109002433A publication Critical patent/CN109002433A/en
Application granted granted Critical
Publication of CN109002433B publication Critical patent/CN109002433B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • G06F40/211Syntactic parsing, e.g. based on context-free grammar [CFG] or unification grammars
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/258Heading extraction; Automatic titling; Numbering

Abstract

The embodiment of the invention provides a text generation method and a text generation device, wherein the method comprises the following steps: obtaining keywords and a title corresponding to a target text to be generated, wherein the keywords are a part of a character sequence consisting of the first character of each sentence of the character sequence in the target text to be generated; generating a first sentence character sequence in the target text to be generated through a pre-trained text generation model based on the keywords and the questions; generating other character sequences except the first sentence character sequence in the target text to be generated through the text generation model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final; and combining the first sentence character sequence and the other character sequences according to the sequence of the first sentence character sequence and the other character sequences to obtain the target text of rhyme.

Description

Text generation method and device
Technical Field
The embodiment of the invention relates to the field of natural language processing, in particular to a text generation method and a text generation device.
Background
A technology for automatically generating texts by using a computer, such as poetry, lyrics, conversation and the like, belongs to the field of natural language processing, and mainly researches and simulates the process and method for generating natural language texts by human beings on the basis of technologies such as computer linguistics, artificial intelligence, deep learning and the like. Poetry is the crystallization of human language, and has characteristics such as style, stick, rhyme, and the like, and Tibetan poetry is a poetry body in a special form in poetry, and it embeds one character in the content that you want to express with the first character of each poetry, and Tibetan poetry has deep meaning, high grade, and high value.
With the rapid development of computer linguistics, artificial intelligence and deep learning, Neural Networks (NN) are currently used as seq2seq (Sequence to Sequence) models of encoders (encoders) and decoders (decoders) to generate texts. Since the seq2seq model generates each sentence character sequence in the text based on probability distribution, there is a problem that the text directly generated by the seq2seq model is not charming, which greatly affects the aesthetic feeling of the generated text. Therefore, the existing text generation method is not reasonable enough and has poor generation effect.
Disclosure of Invention
In view of the above, embodiments of the present invention provide a text generation method and apparatus, and an object of an embodiment of the present invention is to generate a text of an rhyme corresponding to a preset final by combining a text generation model and a preset rhyme rule.
In order to achieve the above purpose, the embodiments of the present invention mainly provide the following technical solutions:
in a first aspect, an embodiment of the present invention provides a text generation method, including: obtaining keywords and a title corresponding to a target text to be generated, wherein the keywords are a part of a character sequence consisting of the first character of each sentence of the character sequence in the target text to be generated; generating a first sentence character sequence in the target text to be generated through a pre-trained text generation model based on the keywords and the questions; generating other character sequences except the first sentence character sequence in the target text to be generated through the text generation model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final; and combining the first sentence character sequence and the other character sequences according to the sequence of the first sentence character sequence and the other character sequences to obtain the target text of rhyme.
In a second aspect, an embodiment of the present invention provides a text generating apparatus, including: the text generating method comprises a first obtaining unit, a first generating unit, a second generating unit and a second obtaining unit, wherein the first obtaining unit is used for obtaining keywords and a title corresponding to a target text to be generated, and the keywords are a part of a text sequence consisting of first words of each sentence of the text sequence in the target text to be generated; the first generating unit is used for generating a first sentence character sequence in the target text to be generated through a pre-trained text generating model based on the keywords and the questions; the second generating unit is used for generating other character sequences except the first sentence character sequence in the target text to be generated through the text generating model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final sound; and the second obtaining unit is used for combining the first sentence character sequence and the other character sequences according to the sequence of generating the first sentence character sequence and the other character sequences to obtain the target text of rhyme.
In a third aspect, an embodiment of the present invention provides a storage medium, where the storage medium includes a stored program, and when the program runs, a device in which the storage medium is located is controlled to execute the text generation method.
In a fourth aspect, an embodiment of the present invention provides an electronic device, including: at least one processor; and at least one memory, bus connected with the processor; the processor and the memory complete mutual communication through the bus; the processor is used for calling the program instructions in the memory to execute the text generation method.
According to the text generation method and device provided by the embodiment of the invention, after the keywords and the titles corresponding to the target texts to be generated are obtained, wherein the keywords are a part of the text sequences composed of the first character of each sentence of the text sequences in the target texts to be generated, the first sentence of the text sequences in the target texts to be generated are generated through a pre-trained text generation model based on the keywords and the titles. Then generating other character sequences except the first sentence character sequence in the target text to be generated through a text generation model and according to a preset rhyme rule at least based on the first sentence character sequence and a preset final; and finally, combining the first sentence character sequence and other character sequences according to the sequence of the first sentence character sequence and other character sequences to obtain the required rhyme target text. In this way, because the other character sequences except the first sentence character sequence in the obtained target text to be generated are rhyme-added according to the preset rhyme-adding rule according to the preset rhyme, the other character sequences are rhyme-added according to the preset rhyme, and the target text generated by the first sentence character sequence and the other character sequences is rhyme-added. Therefore, the effect of generating the text is improved, and the user experience is improved.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flowchart of a text generation method according to a first embodiment of the present invention;
FIG. 2 is a diagram of a text generation system according to a second embodiment of the present invention;
fig. 3 is a flowchart illustrating a text generation method according to a second embodiment of the present invention;
fig. 4 is a schematic structural diagram of a text generating apparatus according to a third embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device in a fourth embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Example one
The embodiment of the invention provides a text generation method which can be applied to various occasions needing to generate rhymes, such as Tibetan poems for generating rhymes, lyrics for generating rhymes, lecture manuscripts for generating rhymes and the like.
Fig. 1 is a schematic flow chart of a text generation method in a first embodiment of the present invention, and referring to fig. 1, the text generation method includes:
s101: obtaining keywords and a title corresponding to a target text to be generated;
the keyword is a part of a character sequence formed by the first character of each sentence of the character sequence in the target text to be generated, and is the name of the target text to be generated.
In the implementation process, the keyword may be text information directly input by a user in a user interface, such as "floret, or text information extracted from a certain picture, and of course, the keyword may also be obtained in other ways, such as text information extracted according to voice information of the user, where the embodiment of the present invention is not specifically limited.
In practical applications, the word number of the keyword may be determined according to the number of sentences corresponding to the text type of the target text to be generated. Here, the text type of the target text to be generated may be set in advance or may be determined by a user operation. The text type of the target text to be generated can be five-language absolute sentence, five-language rhythm poem, seven-language absolute sentence, operators of turnip, dreaming, raccoon sand and the like. Illustratively, when the text type of the target text to be generated is a five-language absolute sentence, the word number of the keyword is less than or equal to 4; when the text type of the target text to be generated is the seven-language rhythm poem, the word number of the keyword is less than or equal to 8; when the text type of the target text to be generated is a word whose brand name is raccoon sand, the number of words of the keyword is less than or equal to 6. Of course, the number of words of the keyword may be set by the user as needed.
In practical applications, the topic may be a topic that is randomly and automatically selected from a preset topic library, such as "operators and singing mei", "geranium and phoenix building", or text information input by a user, such as "a day", "meeting for the first time", or the like, and of course, the topic may also be obtained in other ways, such as matching a topic according to the number of the keyword from a pre-stored topic library, where the embodiment of the present invention is not specifically limited.
For example, when a user wants to generate a target text of rhyme, such as a Tibetan poem of rhyme, the user can directly input keywords to be hidden in the target text, and then after the server for generating the text receives the keywords input by the user, the server can select a topic from the topic library as the name of the target text, so that the keywords and the topic can be obtained. So as to generate a corresponding target text of rhyme according to the keywords and the titles.
In another embodiment of the present invention, when the type of the target text is poem, the seq2seq model may be trained with ancient poems as corpus to obtain a text generation model of Tibetan poems capable of generating rhymes, and then, before the step S101, the text generation method further includes: acquiring ancient poems from a pre-stored ancient poem library; training to obtain a first seq2seq model by using the subject of the ancient poem, a first sentence in the ancient poem and a first word in the first sentence as linguistic data; training to obtain a second seq2seq model by using each sentence in the ancient poems and the corresponding first character as a corpus; training to obtain a third seq2seq model by using each sentence in the ancient poems as a corpus; and determining the first seq2seq model, the second seq2seq model and the third seq2seq model as text generation models.
In a specific implementation process, firstly, the subject of the ancient poem, a first sentence in the ancient poem and a first character in the first sentence are used as linguistic data, and a first seq2seq model is trained, so that the first character and the subject in the obtained keyword can be input into the first seq2seq model to generate a first sentence poem; then, each sentence in the ancient poems and the corresponding first word are used as linguistic data, and a second seq2seq model is trained, so that when the k-th word exists in the obtained keywords and the k-th sentence poem needs to be generated, the k-th word and the k-1 st sentence poem in the obtained keywords can be input into the second seq2seq model to generate the k-th sentence poem, wherein k is a positive integer greater than or equal to 2; and finally, training a third seq2seq model by using each sentence in the ancient poems as a corpus, so that when the g-th character does not exist in the obtained key words and the g-th poem needs to be generated, only the g-1 st sentence can be input into the third seq2seq model to generate the g-th poem, wherein g is a positive integer larger than k.
Of course, in practical applications, text generation models for generating different types of text may be trained using different types of predictions, such as articles, lyrics, poems, dialog, etc. For example, seq2seq models can be trained with existing sentiment as a prediction to create a text generation model that can generate the lingering sentiment of the rhyme. Here, the embodiments of the present invention are not particularly limited.
S102: generating a first sentence character sequence in a target text to be generated through a pre-trained text generation model based on the keywords and the questions;
specifically, after the keywords and the titles are obtained in S101, in order to generate a first sentence character sequence in the target text to be generated, a first character and a title in the keywords may be input into the text generation model to generate the first sentence character sequence.
S103: generating other character sequences except the first sentence character sequence in the target text to be generated through a text generation model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final sound;
specifically, in order to make the generated target text be rhyme, after a first sentence character sequence in the target text to be generated is generated through S102, if there are other characters in the keyword besides the first character, other character sequences in the target text to be generated, which meet a preset rhyme rule, except the first sentence character sequence, can be generated through a text generation model according to the first sentence character sequence, other characters in the keyword, and a preset vowel; if no other words except the first word exist in the keyword, generating other word sequences except the first sentence word sequence in the target text to be generated meeting the preset rhyme rule through a text generation model according to the first sentence word sequence and the preset final sound. In this way, since the other character sequences except the first sentence character sequence in the obtained target text to be generated are generated according to the preset final and meet the preset rhyme-giving rule, the target text generated according to the first sentence character sequence and the other character sequences is rhyme-giving.
In practical application, according to different text types of a target text to be generated, rhyme-entering rules used correspondingly when the target text is generated are different, and exemplarily, when the text types are a poem and an absolute sentence, the corresponding rhyme-entering rules can be an "even sentence-entering rhyme"; when the text type is the word with the name of the word brand being racxi Sha, the corresponding rhyme rule is 'first rhyme to last'. Then, according to different rhyme rules, the method for generating other character sequences in the target text to be generated except the first sentence character sequence may include and is not limited to the following three cases:
in the first case, when the rhyme-entering rule is "rhyme-entering of even sentences", the character sequence of even sentences in the target text to be generated is rhyme-entering.
In a specific implementation process, the step S103 may include the following steps:
step 1031 a: when i is 2, generating a second sentence character sequence through a text generation model at least according to the first sentence character sequence;
step 1031 b: when i is 2N-1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence, wherein N is a positive integer larger than or equal to 2, i is a positive integer smaller than or equal to N, and N is the total sentence number of the character sequence contained in the target text to be generated;
step 1031 c: when i is 2n, determining a first vowel of a last character in the second sentence character sequence as a preset vowel; and generating an ith sentence character sequence which is rhyme with the second sentence character sequence through a text generation model at least according to the (i-1) th sentence character sequence and a preset final.
In practical application, the size of the total sentence number N of the character sequence contained in the target text to be generated can be set by the user according to the need, for example, when the user needs to generate 28 sentences of lyrics, N is 28. The total number of sentences N can also be determined according to the number of sentences corresponding to the text type selected by the user, wherein the text type can be five-language absolute sentences, five-language rhythm poems, seven-language absolute sentences, radish operators, dreams, raccoon sands and the like. Illustratively, when a user wants to generate a five-word absolute from keywords and topics, N is equal to 4; when a user wants to generate a seven-language regular poem according to the keywords and the titles, N is equal to 8; when a user wants to generate a word with the title name raccoon from keywords and titles, N is equal to 6. Of course, the size of the total sentence number N may also be automatically set by the system, and the embodiment of the present invention is not particularly limited.
A specific process of generating a four-sentence character sequence satisfying the rule of even-sentence rhyme is described below by taking an example in which the total sentence number N of the text sequence of the target text to be generated is equal to 4.
Firstly, a first sentence character sequence can be generated through the text generation model according to the keywords and the titles, and secondly, a second sentence character sequence can be generated through the text generation model at least according to the first sentence character sequence; then, a third sentence character sequence can be generated through the text generation model according to at least the second sentence character sequence; finally, in order to make the fourth sentence character sequence rhyme-consonant with the second sentence character sequence, the fourth sentence character sequence rhyme-consonant with the second sentence character sequence can be generated through the text generation model at least according to the first rhyme of the last character in the third sentence character sequence and the second sentence character sequence.
Illustratively, it is assumed that the last word in the second sentence character sequence is "Han", and the last word in the fourth sentence character sequence is "first". In practical application, the pronunciation of a Chinese character is composed of an initial consonant and a final (only the final is a few Chinese characters). For "Han", its initial consonant is h, its final is an, read han together, for "first", its initial consonant is x, and its final is ian, read xian together. Further, table 1 shows a mapping relationship of a part of vowels and vowels, and it can be known from the contents shown in table 1 that the vowels (also called ruts) belonging to "chinese" and "first" are the same, and therefore the fourth sentence character sequence and the second sentence character sequence are rhymes.
Figure BDA0001679217040000071
Figure BDA0001679217040000081
TABLE 1
In the second case, when the rhyme-entering rule is "rhyme-entering of the first sentence + rhyme-entering of the even sentences", in the target text (including the character sequence of N sentences) to be generated, the character sequence of the first sentence is rhyme-entering in addition to the character sequence of the even sentences.
In a specific implementation process, the step S103 may include the following steps:
step 1032 a: when i is 2m, determining the second vowel of the last character in the character sequence of the first sentence as a preset vowel; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through a text generation model at least according to the (i-1) th sentence character sequence and a preset final, wherein m is a positive integer which is larger than or equal to 1, i is a positive integer which is smaller than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated;
step 1032 b: and when i is 2m +1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence.
Illustratively, still taking the case that the total sentence number N of the text sequence of the target text to be generated is equal to 4, when the rhyme-entering rule is "rhyme-entering of the first sentence + rhyme-entering of the even sentence", first, after the first sentence character sequence is obtained, in order to make the rhyme-entering of the first sentence and the rhyme-entering of the even sentence simultaneously satisfied, the second sentence character sequence rhyme-entering with the first sentence character sequence may be generated through the text generation model at least according to the first sentence character sequence and the second rhyme of the last character in the first sentence character sequence; then, a third sentence character sequence can be generated through the text generation model according to at least the second sentence character sequence; finally, in order to make the fourth sentence character sequence rhyme-consistent with the first sentence character sequence, the fourth sentence character sequence rhyme-consistent with the first sentence character sequence can be generated through the text generation model at least according to the third sentence character sequence and the second rhyme of the last character in the first sentence character sequence.
In the third case, when the rhyme-entering rule is "sentence rhyme-entering", the rhymes belonging to the rhymes of the last word in each sentence text sequence are the same in the target text to be generated (including N sentence text sequences).
In a specific implementation process, the step S103 may include the following steps:
step 1033: determining a third final of the last character in the first sentence character sequence as a preset final; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through a text generation model at least based on the ith-1 sentence character sequence and a preset final, wherein i is a positive integer which is greater than or equal to 2, i is a positive integer which is less than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated.
Illustratively, still taking the case that the total sentence number N of the text sequence of the target text to be generated is equal to 4, when the rhyme rule is "sentence rhyme", after the first sentence character sequence is obtained, the last character of the first sentence character sequence can be used as a final, and the other three sentence character sequences rhyme with the first sentence character sequence can be generated through the second final of the last character.
Of course, the rhyme-entering rule may be of other types, such as "alternate rhyme-entering each other", that is, rhyme-entering of odd-numbered sentences and even-numbered sentences, and the embodiment of the present invention is not particularly limited.
In addition, in another embodiment of the present invention, in order to hide the keyword in the character sequence in the target text to be generated, when generating other character sequences in the target text to be generated except for the first sentence character sequence, according to whether there is a keyword in the keyword, step 1031b or step 1032b may include: if the ith character exists in the keyword, generating the ith sentence character sequence through a text generation model according to the ith-1 sentence character sequence and the ith character in the keyword so that the first character in the ith sentence character sequence is the ith character in the keyword; otherwise, generating the ith sentence character sequence through a text generation model according to the ith-1 sentence character sequence.
Specifically, when the ith sentence character sequence in the target text is generated, if the ith character exists in the keyword, at this time, the ith character in the keyword needs to be used as the first character in the ith sentence character sequence to be generated, so that the ith-1 sentence character sequence and the ith character in the keyword can be input into the text generation model to generate the ith sentence character sequence with the ith character in the keyword as the first sentence. When the ith character does not exist in the keyword, the character sequence of the previous sentence of the character sequence of the ith sentence, namely the (i-1) th character sequence can be directly input into the text generation model to generate the character sequence of the ith sentence.
Similarly, in other embodiments of the present invention, in order to hide the keyword in the character sequence in the target text to be generated, a text sequence that needs to be rhyme in the target text to be generated is generated, for example, when the ith sentence character sequence rhyme is rhyme-aligned with the first sentence character sequence, according to whether there is a keyword in the keyword, in step 1032a or step 1033, the step of generating the ith sentence character sequence rhyme-aligned with the first sentence character sequence through a text generation model based on at least the i-1 sentence character sequence and a preset vowel may include: if the ith character exists in the keyword, generating an ith sentence character sequence rhyme which is rhyme with the first sentence character sequence through a text generation model according to the ith-1 sentence character sequence, the ith character in the keyword and a preset vowel; otherwise, generating the ith sentence character sequence which is rhyme with the first sentence character sequence through the text generation model according to the i-1 sentence character sequence and the preset vowel.
In another embodiment of the present invention, if the text type of the target text is a poem, the text generation model may be implemented by using the first seq2seq model, the second seq2seq model and the third seq2seq model, and at this time, the step S102 may include: inputting a first character and a title in the keyword into a first seq2seq model to generate a first sentence character sequence;
in other embodiments of the present invention, if the text type of the target text is a poem, the first seq2seq model, the second seq2seq model, and the third seq2seq model may be adopted to implement the text generation model, and when an ith sentence character sequence in the target text is generated, if an ith character exists in the keyword, the step 1031b or the step 1032b may include: inputting the ith-1 sentence character sequence and the ith character in the keyword into a second seq2seq model to generate an ith sentence character sequence; when generating the ith sentence character sequence in the target text, if the ith character does not exist in the keyword, step 1031b or step 1032b may include: and inputting the ith-1 sentence character sequence into a third seq2seq model to generate an ith sentence character sequence.
Similarly, in other embodiments of the present invention, if the text type of the target text is poem, the text generation model may be implemented by using the first seq2seq model, the second seq2seq model, and the third seq2seq model, in order to hide the keyword in the text sequence in the target text to be generated, and generate a text sequence that needs to be rhyme in the target text to be generated, and if an ith sentence text sequence that is rhyme in the first sentence text sequence exists, according to whether the keyword still exists in the keyword, in step 1032a or step 1033, the step of generating the ith sentence text sequence that is rhyme in the first sentence text sequence through the text generation model based on at least the ith-1 sentence text sequence and a preset vowel may include: if the ith character exists in the keyword, generating an ith sentence character sequence which is rhyme with the first sentence character sequence through a second seq2seq model according to the ith-1 sentence character sequence, the ith character in the keyword and a preset vowel; otherwise, generating the ith sentence character sequence which is rhyme as the first sentence character sequence through the third seq2seq model according to the ith-1 sentence character sequence and the preset vowel.
S104: and combining the first sentence character sequence and other character sequences according to the sequence of the first sentence character sequence and other character sequences to obtain the target text of rhyme.
Illustratively, assuming that the first sentence of character sequence obtained by executing S102 is "liu lai elk or follow-up", and the other character sequences obtained by executing S103 sequentially include three sentence of character sequences of "another man by another man", "flower falling, flowing, and" being unresolved, the first sentence of character sequence and the other sentence of character sequence are combined according to the sequence of generating the first sentence of character sequence and the other sentence of character sequence, and the target text for obtaining rhyme is as follows:
the elk in Liu coming or coming with it,
there are some differences between morals.
The flowers fall into the water and flow towards the things,
the people are ignorant in the way of being busy and floating.
At this point, the process of generating the text of the rhyme is completed.
As can be seen from the above, in the text generation method provided in the embodiment of the present invention, after obtaining the keyword and the title corresponding to the target text to be generated, where the keyword is a part of a text sequence composed of the first word of each sentence of the text sequence in the target text to be generated, first, a first sentence of the text sequence in the target text to be generated is generated through a pre-trained text generation model based on the keyword and the title. Then generating other character sequences except the first sentence character sequence in the target text to be generated through a text generation model and according to a preset rhyme rule at least based on the first sentence character sequence and a preset final; and finally, combining the first sentence character sequence and other character sequences according to the sequence of the first sentence character sequence and other character sequences to obtain the required rhyme target text. In this way, because the other character sequences except the first sentence character sequence in the obtained target text to be generated are rhymed according to the preset rhyme and the preset rhyme-adding rule, the other character sequences are rhyme-added according to the preset rhyme, and the target text generated by the first sentence character sequence and the other character sequences is rhyme-added. Therefore, when the text is generated, the effect of generating the text can be improved, and the user experience is improved.
Example two
Based on the foregoing embodiments, the present embodiment provides a text generation method, which is applied to the following scenarios: the text type of the target text to be generated is poetry, the total sentence number N of the target text to be generated is 4, the questions are randomly selected from a preset question library, and the rhyme-giving rule corresponding to the target text is 'rhyme-giving by even sentences'.
An embodiment of the present invention provides a text generation system, as shown in fig. 2, the system includes: a topic library 201, a first seq2seq model 202, a second seq2seq model 203 and a third seq2seq model 204; wherein, the topic library 101 is used for randomly selecting the purpose of the target title after obtaining the keyword; the first seq2seq model 202 is trained by using the subject of the ancient poetry, the first sentence poetry in the ancient poetry and the first character of the first sentence poetry as linguistic data, and is used for generating a first sentence according to the input key words and the subject; the second seq2seq model 203 is trained by using each sentence of ancient poems and the first word corresponding to each sentence of ancient poems as corpus and is used for generating the next sentence of ancient poems according to the input key words and the previous sentence of ancient poems; the third seq2seq model 204 is trained by using each poem of the ancient poems as corpus, and is used for generating the next poem according to the previous poem, and supplementing the missing poems when the total number of the keywords in the keywords is less than the total number of the sentences N.
In practical applications, the seq2seq models, such as the first seq2seq model, the second seq2seq model, the third seq2seq model, and so on, include: an Encoder (Encoder) and a Decoder (Decoder), the Encoder encoding an input text sequence a into a state vector S by learning the input text sequence a after inputting the text sequence a into the seq2seq model, and then transferring the state vector S to the Decoder, the Decoder outputting another text sequence B by learning the state vector S using a search algorithm such as Beam search, greedy search, etc.
In the implementation process, in order to generate the character sequence B of the rhyme, that is, the final of the last character in the character sequence B and the preset final belong to the same final, if the decoder uses Beam search when decoding the state vector S, a plurality of character sequences B can be obtained according to probability sequencing, and then the preset final is used as a limiting condition, and the last character final and the character sequence B belonging to the same final as the preset final are searched as the generation results. Of course, if the decoder uses a greedy search when decoding the state vector S, the decoding strategy may be modified by a preset final when decoding the state vector S to generate the text sequence B of the rhyme.
Fig. 3 is a schematic flowchart of a text generation method in the second embodiment of the present invention, and as shown in fig. 3, the method includes:
s301: obtaining a keyword;
s302: randomly determining a target question from a preset question library;
s303: inputting a first character and a target title in a keyword into a first seq2seq model to generate a first sentence poem;
s304: determining whether a second word exists in the keyword;
if it is determined that the second word does not exist in the keyword, performing S305a to generate a second poem; otherwise, S305b is executed to generate a second sentence poem.
S305 a: inputting the first sentence poems into a third seq2seq model to generate a second sentence poem;
after the second sentence poem is obtained by performing S305a, S306 to S307 are performed to obtain a third sentence poem and a fourth sentence poem rhymed to the second sentence poem.
S306: inputting the second sentence poems into a third seq2seq model to generate a third sentence poem;
s307: inputting the final sound of the last character in the third sentence poem and the second sentence poem into a third seq2seq model to generate a fourth sentence poem rhyme;
in practical application, after inputting the final of the last character in the third poem and the second poem into the third seq2seq model, firstly, the third seq2seq model can generate a plurality of fourth poems according to the probability according to the third poem, and then the third seq2seq model can filter out the fourth poems which are rhymes lingering to the second poem by taking the final of the last character in the second poem as a screening condition.
S305 b: inputting the first sentence poem and a second word in the keyword into a second seq2seq model to generate a second sentence poem;
after the second sentence poem is obtained in execution of S305b, S308 is executed.
S308, determining whether a third word exists in the keyword;
if the third character does not exist in the keyword, executing S306 to S307 to obtain a third sentence poem and a fourth sentence poem rhyme; otherwise, S309 is performed to generate a third sentence poem.
S309: inputting the second sentence poem and a third character in the keyword into a second seq2seq model to generate a third sentence poem;
after the third sentence poem is obtained in the step S309, the step S310 is performed.
S310, determining whether a fourth word exists in the keyword;
if it is determined that the fourth word does not exist in the keyword, executing S307 to obtain a fourth sentence poem rhyme; otherwise, S311 is performed to generate a fourth sentence poem rhyme.
S311: inputting the third sentence poem, the fourth character in the keyword and the final sound of the last character in the second sentence poem into a second seq2seq model to generate the fourth sentence poem which is rhyme together with the second sentence poem.
In practical application, after inputting the third sentence poem, the fourth word in the keyword and the final sound of the last word in the second sentence poem into the second seq2seq model, firstly, the second seq2seq model can generate a plurality of fourth sentence poems with the first word as the fourth word according to the third sentence poem and the fourth word in the keyword according to probability, and then the third seq2seq model can use the final sound of the last word in the second sentence poem as a screening condition to filter out the fourth sentence poem with the rhyme of the second sentence poem and the first word as the fourth word.
S312: and arranging the first sentence poems to the fourth sentence poems according to the generated sequence to obtain a target text of rhyme.
And finally, after the first sentence poem, the second sentence poem, the third sentence poem and the fourth sentence poem are obtained, the first sentence poem to the fourth sentence poem can be arranged according to the generated sequence to obtain the target text of rhyme.
As can be seen from the above, in the text generating method provided in the embodiment of the present invention, after the first sentence poem, the second sentence poem, and the third sentence poem are obtained, the fourth sentence poem rhyme rh. Thus, when the text is generated, the effect of the generated text can be improved, and the user experience can be improved.
EXAMPLE III
Based on the same inventive concept, as an implementation of the foregoing method, an embodiment of the present invention provides a text generation apparatus, where an embodiment of the apparatus corresponds to the foregoing method embodiment, and for convenience of reading, details in the foregoing method embodiment are not repeated in this apparatus embodiment one by one, but it should be clear that the apparatus in this embodiment can correspondingly implement all the contents in the foregoing method embodiment.
Fig. 4 is a schematic structural diagram of a text generating apparatus according to a third embodiment of the present invention, and referring to fig. 4, the apparatus 40 includes: a first obtaining unit 401, a first generating unit 402, a second generating unit 403, and a second obtaining unit 404, where the first obtaining unit 401 is configured to obtain a keyword and a title corresponding to a target text to be generated, where the keyword is a part of a text sequence composed of first words of each sentence of the text sequence in the target text to be generated; a first generating unit 402, configured to generate a first sentence character sequence in a target text to be generated through a pre-trained text generation model based on a keyword and a topic; a second generating unit 403, configured to generate, through a text generation model, other text sequences in the target text to be generated, except for the first sentence text sequence, according to a preset rhyme rule based on at least the first sentence text sequence and a preset final; a second obtaining unit 404, configured to combine the first sentence character sequence and the other character sequences according to the sequence of generating the first sentence character sequence and the other character sequences, so as to obtain a target text of rhyme.
In the embodiment of the present invention, the second generating unit is configured to generate a second sentence character sequence through a text generation model at least according to the first sentence character sequence when i is 2; when i is 2N-1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence, wherein N is a positive integer larger than or equal to 2, i is a positive integer smaller than or equal to N, and N is the total sentence number of the character sequence contained in the target text to be generated; when i is 2n, determining a first vowel of a last character in the second sentence character sequence as a preset vowel; and generating an ith sentence character sequence which is rhyme with the second sentence character sequence through a text generation model at least according to the (i-1) th sentence character sequence and a preset final.
In the embodiment of the present invention, the second generating unit is configured to determine a second final of a last word in the first sentence word sequence as a preset final when i is 2 m; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through a text generation model at least according to the (i-1) th sentence character sequence and a preset final, wherein m is a positive integer which is larger than or equal to 1, i is a positive integer which is smaller than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated; and when i is 2m +1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence.
In the embodiment of the invention, the second generating unit is used for generating the ith sentence character sequence according to the ith-1 sentence character sequence and the ith character in the keyword through a text generating model if the ith character exists in the keyword, so that the first character in the ith sentence character sequence is the ith character in the keyword; otherwise, generating the ith sentence character sequence through a text generation model according to the ith-1 sentence character sequence.
In other embodiments of the present invention, the apparatus further comprises: the device comprises an acquisition unit, a first training unit, a second training unit, a third training unit and a determination unit, wherein the acquisition unit is used for acquiring ancient poems from a pre-stored ancient poem library; the first training unit is used for training to obtain a first seq2seq model by using the subject of the ancient poetry, a first sentence in the ancient poetry and a first word in the first sentence as linguistic data; the second training unit is used for training each sentence in the ancient poetry and the corresponding first character as a corpus to obtain a second seq2seq model; the third training unit is used for training to obtain a third seq2seq model by using each sentence in the ancient poems as a corpus; and the determining unit is used for determining the first seq2seq model, the second seq2seq model and the third seq2seq model as the text generation model.
In the embodiment of the invention, a first generating unit is used for inputting a first character and a title in a keyword into a first seq2seq model to generate a first sentence character sequence; the second generation unit is used for inputting the ith-1 sentence character sequence and the ith character in the keyword into a second seq2seq model to generate the ith sentence character sequence if the ith character exists in the keyword; and the system is also used for inputting the ith-1 sentence character sequence into the third seq2seq model to generate the ith sentence character sequence if the ith character does not exist in the keyword.
In the embodiment of the present invention, the second generating unit is configured to determine a third final of a last word in the first sentence character sequence as a preset final; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through a text generation model at least based on the ith-1 sentence character sequence and a preset final, wherein i is a positive integer which is greater than or equal to 2, i is a positive integer which is less than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated.
The text generation device comprises a processor and a memory, wherein the first obtaining unit, the first generation unit, the second obtaining unit and the like are stored in the memory as program units, and the processor executes the program units stored in the memory to realize corresponding functions.
The Processor may be implemented by a Central Processing Unit (CPU), a microprocessor Unit (MPU), a Digital Signal Processor (DSP), a Field Programmable Gate Array (FPGA), or the like.
The Memory may include volatile Memory in a computer readable medium, Random Access Memory (RAM), and/or nonvolatile Memory such as Read Only Memory (ROM) or Flash Memory (Flash RAM), and the Memory includes at least one Memory chip.
Based on the same inventive concept, embodiments of the present invention provide a storage medium having a program stored thereon, the program implementing the above-described text generation method when executed by a processor.
Based on the same inventive concept, an embodiment of the present invention provides a processor, where the processor is configured to run a program, and the program executes the text generation method when running.
Since the text generating apparatus described in this embodiment is an apparatus capable of executing the text generating method in the embodiment of the present invention, based on the text generating method described in the embodiment of the present invention, a person skilled in the art can understand the specific implementation manner of the text generating apparatus of this embodiment and various variations thereof, and therefore, how the text generating apparatus implements the text generating method in the embodiment of the present invention is not described in detail herein. The device used by those skilled in the art to implement the text generation method in the embodiments of the present invention is within the scope of the present application.
In practical applications, the text generation apparatus can be applied to electronic devices. The electronic device may be implemented in various forms. For example, the electronic device described in the embodiments of the present invention may include a mobile terminal such as a smart speaker, a mobile phone, a tablet computer, a notebook computer, a palm top computer, a Personal Digital Assistant (PDA), a Portable Media Player (PMP), a navigation device, a wearable device, a smart band, a pedometer, and a fixed terminal such as a smart television, a desktop computer, a server, and the like.
Example four
Based on the same inventive concept, the embodiment of the invention provides electronic equipment. Fig. 5 is a schematic structural diagram of an electronic device in a fourth embodiment of the present invention, and referring to fig. 5, the electronic device 50 includes: at least one processor 51; and at least one memory 52, a bus 53 connected to the processor 51; the processor 51 and the memory 52 complete mutual communication through the bus 53; the processor 51 is configured to call program instructions in the memory 52 to perform the following steps: obtaining keywords and a title corresponding to a target text to be generated, wherein the keywords are a part of a character sequence consisting of the first character of each sentence of the character sequence in the target text to be generated; generating a first sentence character sequence in a target text to be generated through a pre-trained text generation model based on the keywords and the questions; generating other character sequences except the first sentence character sequence in the target text to be generated through a text generation model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final sound; and combining the first sentence character sequence and other character sequences according to the sequence of the first sentence character sequence and other character sequences to obtain the target text of rhyme.
In the embodiment of the present invention, when the processor calls the program instruction, the following steps may be further performed: when i is 2, generating a second sentence character sequence through a text generation model at least according to the first sentence character sequence; when i is 2N-1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence, wherein N is a positive integer larger than or equal to 2, i is a positive integer smaller than or equal to N, and N is the total sentence number of the character sequence contained in the target text to be generated; when i is 2n, determining a first vowel of a last character in the second sentence character sequence as a preset vowel; and generating an ith sentence character sequence which is rhyme with the second sentence character sequence through a text generation model at least according to the (i-1) th sentence character sequence and a preset final.
In the embodiment of the present invention, when the processor calls the program instruction, the following steps may be further performed: when i is 2m, determining the second vowel of the last character in the character sequence of the first sentence as a preset vowel; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through a text generation model at least according to the (i-1) th sentence character sequence and a preset final, wherein m is a positive integer which is larger than or equal to 1, i is a positive integer which is smaller than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated; and when i is 2m +1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence.
In the embodiment of the present invention, when the processor calls the program instruction, the following steps may be further performed: if the ith character exists in the keyword, generating the ith sentence character sequence through a text generation model according to the ith-1 sentence character sequence and the ith character in the keyword so that the first character in the ith sentence character sequence is the ith character in the keyword; otherwise, generating the ith sentence character sequence through a text generation model according to the ith-1 sentence character sequence.
In the embodiment of the present invention, when the processor calls the program instruction, the following steps may be further performed: acquiring ancient poems from a pre-stored ancient poem library; training to obtain a first seq2seq model by using the subject of the ancient poem, a first sentence in the ancient poem and a first word in the first sentence as linguistic data; training to obtain a second seq2seq model by using each sentence in the ancient poems and the corresponding first character as a corpus; training to obtain a third seq2seq model by using each sentence in the ancient poems as a corpus; and determining the first seq2seq model, the second seq2seq model and the third seq2seq model as text generation models.
In the embodiment of the present invention, when the processor calls the program instruction, the following steps may be further performed: inputting a first character and a title in the keyword into a first seq2seq model to generate a first sentence character sequence; if the ith character exists in the keyword, inputting the ith-1 sentence character sequence and the ith character in the keyword into a second seq2seq model to generate an ith sentence character sequence; and if the ith character does not exist in the keyword, inputting the ith-1 sentence character sequence into a third seq2seq model to generate the ith sentence character sequence.
In the embodiment of the present invention, when the processor calls the program instruction, the following steps may be further performed: determining a third final of the last character in the first sentence character sequence as a preset final; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through a text generation model at least based on the ith-1 sentence character sequence and a preset final, wherein i is a positive integer which is greater than or equal to 2, i is a positive integer which is less than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, Compact disk Read-Only Memory (CD-ROM), optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, RAM and/or non-volatile memory, such as ROM or Flash RAM. The memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. The computer-readable storage medium may be a ROM, a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a magnetic Random Access Memory (FRAM), a Flash Memory (Flash Memory), a magnetic surface Memory, an optical Disc, or a Compact Disc Read-Only Memory (CD-ROM), among other memories; or flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium which can be used to store information and which can be accessed by a computing device; but may also be various electronic devices such as mobile phones, computers, tablet devices, personal digital assistants, etc., that include one or any combination of the above-mentioned memories. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above are merely examples of the present invention, and are not intended to limit the present invention. Various modifications and alterations to this invention will become apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of the claims of the present invention.

Claims (8)

1. A method of text generation, the method comprising:
obtaining keywords and a title corresponding to a target text to be generated, wherein the keywords are a part of a character sequence consisting of the first character of each sentence of the character sequence in the target text to be generated;
generating a first sentence character sequence in the target text to be generated through a pre-trained text generation model based on the keywords and the questions;
generating other character sequences except the first sentence character sequence in the target text to be generated through the text generation model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final;
combining the first sentence character sequence and the other character sequences according to the sequence of generating the first sentence character sequence and the other character sequences to obtain a target text of rhyme retention; generating other character sequences in the target text to be generated except the first sentence character sequence through the text generation model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final, wherein the character sequences comprise:
when i is 2, generating a second sentence character sequence through the text generation model at least according to the first sentence character sequence;
when i is 2N-1, generating the ith sentence character sequence through the text generation model at least according to the ith-1 sentence character sequence, wherein N is a positive integer larger than or equal to 2, i is a positive integer smaller than or equal to N, and N is the total sentence number of the character sequence contained in the target text to be generated;
when i is 2n, determining the first vowel of the last character in the second sentence character sequence as the preset vowel; generating an ith sentence character sequence rhyme which is rhyme with the second sentence character sequence through the text generation model at least according to the i-1 sentence character sequence and the preset vowel;
generating the ith sentence character sequence through the text generation model at least according to the ith-1 sentence character sequence, wherein the generating comprises the following steps:
if the ith character exists in the keyword, generating an ith sentence character sequence through the text generation model according to the ith-1 sentence character sequence and the ith character in the keyword, so that the first character in the ith sentence character sequence is the ith character in the keyword; otherwise, generating the ith sentence character sequence through the text generation model according to the ith-1 sentence character sequence.
2. The method according to claim 1, wherein the generating, by the text generation model, other text sequences in the target text to be generated except for the first sentence text sequence according to a preset rhyme rule based on at least the first sentence text sequence and a preset final sound comprises:
when i is 2m, determining the second final of the last character in the first sentence character sequence as the preset final; generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through the text generation model at least according to the ith-1 sentence character sequence and the preset vowel, wherein m is a positive integer larger than or equal to 1, i is a positive integer smaller than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated;
when i is 2m +1, generating an ith sentence character sequence through the text generation model at least according to the ith-1 sentence character sequence;
generating the ith sentence character sequence through the text generation model at least according to the ith-1 sentence character sequence, wherein the generating comprises the following steps:
if the ith character exists in the keyword, generating an ith sentence character sequence through the text generation model according to the ith-1 sentence character sequence and the ith character in the keyword, so that the first character in the ith sentence character sequence is the ith character in the keyword; otherwise, generating the ith sentence character sequence through the text generation model according to the ith-1 sentence character sequence.
3. The method of claim 1 or 2, wherein prior to obtaining keywords and topics, the method further comprises:
acquiring ancient poems from a pre-stored ancient poem library;
training to obtain a first seq2seq model by using the subject of the ancient poem, a first sentence in the ancient poem and a first word in the first sentence as linguistic data;
training to obtain a second seq2seq model by using each sentence in the ancient poems and the corresponding first word as a corpus;
training to obtain a third seq2seq model by using each sentence in the ancient poems as a corpus;
determining the first, second and third seq2seq models as the text generation model.
4. The method according to claim 3, wherein the generating a first sentence character sequence in the target text to be generated through a pre-trained text generation model based on the keyword and the topic comprises: inputting a first character and the title in the keyword into the first seq2seq model to generate a first sentence character sequence;
if the ith character exists in the keyword, generating the ith sentence character sequence according to the ith-1 sentence character sequence and the ith character in the keyword through the text generation model, wherein the generating of the ith sentence character sequence comprises the following steps: inputting the ith-1 sentence character sequence and the ith character in the keyword into the second seq2seq model to generate an ith sentence character sequence;
if the ith character does not exist in the keyword, generating an ith sentence character sequence according to the ith-1 sentence character sequence, wherein the step of generating the ith sentence character sequence comprises the following steps: and inputting the ith-1 sentence character sequence into the third seq2seq model to generate an ith sentence character sequence.
5. The method according to claim 1, wherein the generating, by the text generation model, other text sequences in the target text to be generated except for the first sentence text sequence according to a preset rhyme rule based on at least the first sentence text sequence and a preset final sound comprises:
determining a third final of the last character in the first sentence character sequence as the preset final; and generating an ith sentence character sequence which is in rhyme with the first sentence character sequence through the text generation model at least based on the ith-1 sentence character sequence and the preset vowel, wherein i is a positive integer greater than or equal to 2, i is a positive integer less than or equal to N, and N is the total sentence number of the character sequences contained in the target text to be generated.
6. An apparatus for generating text, the apparatus comprising: a first obtaining unit, a first generating unit, a second generating unit, and a second obtaining unit, wherein,
the first obtaining unit is used for obtaining a keyword and a title corresponding to a target text to be generated, wherein the keyword is a part of a character sequence formed by the first character of each sentence of the character sequence in the target text to be generated;
the first generating unit is used for generating a first sentence character sequence in the target text to be generated through a pre-trained text generating model based on the keywords and the questions;
the second generating unit is used for generating other character sequences except the first sentence character sequence in the target text to be generated through the text generating model according to a preset rhyme rule at least based on the first sentence character sequence and a preset final sound;
the second obtaining unit is configured to combine the first sentence character sequence and the other character sequences according to the sequence of generating the first sentence character sequence and the other character sequences to obtain a target text for rhyme retention;
the second generating unit is used for generating a second sentence character sequence through a text generating model at least according to the first sentence character sequence when i is 2; when i is 2N-1, generating the ith sentence character sequence through a text generation model at least according to the ith-1 sentence character sequence, wherein N is a positive integer larger than or equal to 2, i is a positive integer smaller than or equal to N, and N is the total sentence number of the character sequence contained in the target text to be generated; when i is 2n, determining a first vowel of a last character in the second sentence character sequence as a preset vowel; generating an ith sentence character sequence which is rhyme-added with the second sentence character sequence through a text generation model at least according to the i-1 th sentence character sequence and a preset final;
the second generation unit is used for generating an ith sentence character sequence according to the ith-1 sentence character sequence and the ith character in the keyword through a text generation model if the ith character exists in the keyword, so that the first character in the ith sentence character sequence is the ith character in the keyword; otherwise, generating the ith sentence character sequence through a text generation model according to the ith-1 sentence character sequence.
7. A storage medium characterized by comprising a stored program, wherein a device on which the storage medium is located is controlled to execute the text generation method according to any one of claims 1 to 5 when the program is executed.
8. An electronic device, characterized in that the electronic device comprises:
at least one processor;
and at least one memory, bus connected with the processor;
the processor and the memory complete mutual communication through the bus; the processor is configured to invoke program instructions in the memory to perform the text generation method of any of claims 1 to 5.
CN201810540691.2A 2018-05-30 2018-05-30 Text generation method and device Active CN109002433B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810540691.2A CN109002433B (en) 2018-05-30 2018-05-30 Text generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810540691.2A CN109002433B (en) 2018-05-30 2018-05-30 Text generation method and device

Publications (2)

Publication Number Publication Date
CN109002433A CN109002433A (en) 2018-12-14
CN109002433B true CN109002433B (en) 2022-04-01

Family

ID=64574195

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810540691.2A Active CN109002433B (en) 2018-05-30 2018-05-30 Text generation method and device

Country Status (1)

Country Link
CN (1) CN109002433B (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111767694B (en) * 2019-03-26 2024-04-16 北京京东尚科信息技术有限公司 Text generation method, apparatus and computer readable storage medium
CN110134960A (en) * 2019-05-15 2019-08-16 北京奇艺世纪科技有限公司 A kind of generation method and relevant device of text
CN110209803B (en) * 2019-06-18 2023-11-14 腾讯科技(深圳)有限公司 Story generation method, apparatus, computer device and storage medium
CN110377902B (en) * 2019-06-21 2023-07-25 北京百度网讯科技有限公司 Training method and device for descriptive text generation model
CN110287489B (en) * 2019-06-24 2023-07-28 北京大米科技有限公司 Text generation method, device, storage medium and electronic equipment
CN110705310B (en) * 2019-09-20 2023-07-18 北京金山数字娱乐科技有限公司 Article generation method and device
CN111444679A (en) * 2020-03-27 2020-07-24 北京小米松果电子有限公司 Poetry generation method and device, electronic equipment and storage medium
CN111783455A (en) * 2020-07-13 2020-10-16 网易(杭州)网络有限公司 Training method and device of text generation model and text generation method and device
CN111898339B (en) * 2020-07-28 2023-07-21 中国平安人寿保险股份有限公司 Ancient poetry generating method, device, equipment and medium based on constraint decoding
CN116011430B (en) * 2023-03-22 2024-04-02 暗链科技(深圳)有限公司 Vowel duplication elimination method, nonvolatile readable storage medium and electronic equipment
CN116011431A (en) * 2023-03-22 2023-04-25 暗链科技(深圳)有限公司 Method for generating mnemonic words and electronic equipment
CN115994532A (en) * 2023-03-22 2023-04-21 暗链科技(深圳)有限公司 Corpus classification method, nonvolatile readable storage medium and electronic device

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102385596A (en) * 2010-09-03 2012-03-21 腾讯科技(深圳)有限公司 Verse searching method and device
CN105185373A (en) * 2015-08-06 2015-12-23 百度在线网络技术(北京)有限公司 Rhythm-level prediction model generation method and apparatus, and rhythm-level prediction method and apparatus
CN105551481A (en) * 2015-12-21 2016-05-04 百度在线网络技术(北京)有限公司 Rhythm marking method of voice data and apparatus thereof
CN105955964A (en) * 2016-06-13 2016-09-21 北京百度网讯科技有限公司 Method and apparatus for automatically generating poem
CN106569995A (en) * 2016-09-26 2017-04-19 天津大学 Method for automatically generating Chinese poetry based on corpus and metrical rule
CN106776517A (en) * 2016-12-20 2017-05-31 科大讯飞股份有限公司 Automatic compose poem method and apparatus and system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102385596A (en) * 2010-09-03 2012-03-21 腾讯科技(深圳)有限公司 Verse searching method and device
CN105185373A (en) * 2015-08-06 2015-12-23 百度在线网络技术(北京)有限公司 Rhythm-level prediction model generation method and apparatus, and rhythm-level prediction method and apparatus
CN105551481A (en) * 2015-12-21 2016-05-04 百度在线网络技术(北京)有限公司 Rhythm marking method of voice data and apparatus thereof
CN105955964A (en) * 2016-06-13 2016-09-21 北京百度网讯科技有限公司 Method and apparatus for automatically generating poem
CN106569995A (en) * 2016-09-26 2017-04-19 天津大学 Method for automatically generating Chinese poetry based on corpus and metrical rule
CN106776517A (en) * 2016-12-20 2017-05-31 科大讯飞股份有限公司 Automatic compose poem method and apparatus and system

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
Can M achine Generate Traditional Chinese Po etry? A Feigenbaum Test;Qixin Wang 等;《Springer International Publishing AG 2016》;20161231;第1-13页 *
Generating Chinese Classical Poems with RNN Encoder-Decoder;Xiaoyuan Yi 等;《Springer International Publishing AG 2017》;20171231;第1-13页 *
基于深度学习技术的中国传统诗歌生成方法研究;王哲;《中国优秀博硕士学位论文全文数据库(硕士) 信息科技辑》;20180115;第1-15页 *
王哲.基于深度学习技术的中国传统诗歌生成方法研究.《中国优秀博硕士学位论文全文数据库(硕士) 信息科技辑》.2018,第1-15页. *

Also Published As

Publication number Publication date
CN109002433A (en) 2018-12-14

Similar Documents

Publication Publication Date Title
CN109002433B (en) Text generation method and device
CN110717017B (en) Method for processing corpus
Yi et al. Generating chinese classical poems with rnn encoder-decoder
US8589163B2 (en) Adapting language models with a bit mask for a subset of related words
CN111639163A (en) Problem generation model training method, problem generation method and related equipment
KR20210146368A (en) End-to-end automatic speech recognition for digit sequences
CN111951780B (en) Multitasking model training method for speech synthesis and related equipment
Zuberbühler Evolutionary roads to syntax
CN110209803B (en) Story generation method, apparatus, computer device and storage medium
US11282502B2 (en) Method for utterance generation, smart device, and computer readable storage medium
CN114861653B (en) Language generation method, device, equipment and storage medium for virtual interaction
CN112528637A (en) Text processing model training method and device, computer equipment and storage medium
CN111767394A (en) Abstract extraction method and device based on artificial intelligence expert system
KR20200087977A (en) Multimodal ducument summary system and method
CN117115303A (en) Method, system, computing device and storage medium for content generation
Roque Language technology enables a poetics of interactive generation
CN116127003A (en) Text processing method, device, electronic equipment and storage medium
CN114880485A (en) Reading comprehension answer generation method and device, computer equipment and storage medium
JP2021193608A (en) Utterance generation device, utterance generation method, and computer program
CN111126066B (en) Method and device for determining Chinese congratulation technique based on neural network
CN114428838A (en) Content recall method and device, computer equipment and storage medium
CN112861546A (en) Method and device for acquiring text semantic similarity value, storage medium and electronic equipment
WO2019087064A1 (en) Language learning system and methods
Thabet et al. Q&A Generation for Flashcards Within a Transformer-Based Framework
CN110377915B (en) Text emotion analysis method and device, storage medium and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20221206

Address after: 210034 floor 8, building D11, Hongfeng Science Park, Nanjing Economic and Technological Development Zone, Jiangsu Province

Patentee after: New Technology Co.,Ltd.

Address before: 100094 1001, 10th floor, office building a, 19 Zhongguancun Street, Haidian District, Beijing

Patentee before: MOBVOI INFORMATION TECHNOLOGY Co.,Ltd.