A poetry generation method, device, computer equipment and storage medium

By obtaining topic information, inputting the poetry prediction model and n-gram language model, combining rhyme rules and repetition rate screening, and using the beam search method and Bayesian formula, the problem of inconsistency between the training and prediction stages of the deep learning poetry generation model is solved. Improved the quality of poetry, achieving better rhyme and non-repetition.

CN112101006BInactive Publication Date: 2024-08-30CHINA PING AN LIFE INSURANCE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202010961561.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-14
Publication Date
2024-08-30
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Poetry generation models based on deep learning are inconsistent in the training and prediction phases, resulting in poor quality in generated poems with rhyme and repeated character problems.

Method used

By obtaining the theme information of the poems to be generated, input the poetry prediction model to generate an initial collection of candidate poems, use the n-gram language model and rhyme rules to filter, calculate the repetition rate, and combine the beam search method and Bayesian formula for screening to improve the fluency of the poems. sex, rhyme and non-repetition.

Benefits of technology

The fluency, rhyme and non-repetition of generated poetry are improved, and the problem of poor quality of generated poetry in the existing technology is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112101006B
    Figure CN112101006B
Patent Text Reader

Abstract

This case involves artificial intelligence and provides a poetry generation method, which includes: obtaining the theme information of the poem to be generated; inputting the theme information into the poem prediction model to generate an initial candidate poem set; inputting the candidate poems in the initial candidate poem set into a preset n‑gram language model to generate a target candidate poem set; performing rhyme screening on the candidate poems in the target candidate poem set according to the preset rhyme rules, and calculating the repetition rate of each poem to be screened; and screening the poem repetition rate of multiple poems to be screened according to the repetition rate to obtain the target poem. The initial candidate poem set predicted by the beam search method is screened by poem fluency, poem rhyme, and poem repetition rate, which improves the fluency, rhyme, and non-repetitiveness of the generated poems, and solves the problem of poor quality of generated poems in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence, and in particular to a poetry generation method, device, computer equipment and storage medium. Background Art

[0002] Poetry is part of the essence of Chinese culture. After a long period of accumulation, a lot of high-quality ancient and modern poetry corpora have been produced. With the rapid development of deep learning technology, models based on deep learning have also been applied to poetry creation. The poetry prediction model learns the existing ancient or modern poetry corpora, learns their writing characteristics and methods, and then imitates, creates, and regenerates them, thereby realizing the function of automatically generating poetry.

[0003] At present, the poetry generation model based on deep learning generates poetry in a sentence-by-sentence loop. Specifically, the poetry generation training set is first constructed through keywords, and then the current line of poetry is predicted through keywords and previous information. This cycle is repeated four times to obtain the entire poem. During the training process, the teach forcing method is used to predict the word at the current time t based on the word at time t-1 in the real poem and the current context vector. However, in the infer stage, since it is impossible to know the real output word, at the current time t, the decoder will predict the word at the current time t based on the previously predicted word at time t-1. It can be clearly seen that this method is inconsistent in the training and prediction stages. The generated poems have problems such as no rhyme and repeated characters, which leads to poor quality of generated poems. Summary of the invention

[0004] The present invention provides a poetry generation method, device, computer equipment and storage medium to solve the problem of poor quality of generated poetry.

[0005] A poetry generation method, comprising:

[0006] Obtain the subject information of the poem to be generated;

[0007] Inputting the topic information into a poetry prediction model to generate an initial candidate poetry set;

[0008] Input the candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set;

[0009] Performing rhyme screening on the candidate poems in the target candidate poetry set according to a preset rhyme rule to obtain a plurality of poems to be screened;

[0010] Calculate the repetition rate of each poem to be screened;

[0011] The repetition rates of multiple poems to be screened are screened according to the repetition rates to obtain target poems.

[0012] A poetry generation device, comprising:

[0013] An acquisition module is used to obtain the theme information of the poem to be generated;

[0014] A generation module, inputting the subject information into a poetry prediction model to generate an initial candidate poetry set;

[0015] The fluency screening module inputs the candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set;

[0016] A rhyme screening module performs rhyme screening on the candidate poems in the target candidate poem set according to preset rhyme rules to obtain multiple poems to be screened;

[0017] A calculation module, calculating the repetition rate of each poem to be screened;

[0018] The repetition rate screening module screens the repetition rate of multiple poems to be screened according to the repetition rate to obtain the target poem.

[0019] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned poetry generation method when executing the computer program.

[0020] A computer-readable storage medium stores a computer program, which implements the steps of the above-mentioned poetry generation method when executed by a processor.

[0021] In one of the schemes implemented by the above-mentioned poetry generation method, device, computer equipment and storage medium, the subject information of the poem to be generated is obtained; the subject information is input into the poem prediction model to generate an initial candidate poem set; the candidate poems in the initial candidate poem set are input into a preset n-gram language model to generate a target candidate poem set; the candidate poems in the target candidate poem set are subjected to rhyme screening according to preset rhyme rules, and the repetition rate of each poem to be screened is calculated; the poem repetition rate of multiple poems to be screened is screened according to the repetition rate to obtain the target poem. The initial candidate poem set predicted by the beam search method is screened by poem fluency, poem rhyme and poem repetition rate, which improves the fluency, rhyme and non-repetitiveness of the generated poem, and solves the problem of poor quality of generated poems in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0023] Figure 1 It is a schematic diagram of an application environment of a method for generating a presentation in one embodiment of the present invention;

[0024] Figure 2 is a flow chart of a method for generating a presentation in one embodiment of the present invention;

[0025] Figure 3 is another flow chart of a method for generating a presentation in one embodiment of the present invention;

[0026] Figure 4 is another flow chart of a method for generating a presentation in one embodiment of the present invention;

[0027] Figure 5 is another flow chart of a method for generating a presentation in one embodiment of the present invention;

[0028] Figure 6 is another flow chart of a method for generating a presentation in one embodiment of the present invention;

[0029] Figure 7 is another flow chart of a method for generating a presentation in one embodiment of the present invention;

[0030] Figure 8 is another flow chart of a method for generating a presentation in one embodiment of the present invention;

[0031] Fig. 9 It is a principle block diagram of a presentation document generating device in one embodiment of the present invention;

[0032] Fig.10 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION

[0033] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0034] The poetry generation method provided by the present invention can be applied to Figure 1 In an application environment, a server communicates with a client through a network.

[0035] In one embodiment, if Figure 2 As shown, a poetry generation method is provided, comprising the following steps:

[0036] S10: Obtain the subject information of the poem to be generated.

[0037] Understandably, when a poem needs to be generated, the client can provide subject information input by the user, and the server can receive the subject information fed back by the client. The subject information includes the subject words of the generated poem, for example, the subject information can be "bright moon", "frost", "raise your head" or "hometown", etc.

[0038] S20: Input the topic information into the poetry prediction model to generate an initial candidate poetry set.

[0039] In one embodiment, if Figure 3 As shown, in step S20, that is, inputting the subject information into the poetry prediction model to generate an initial candidate poetry set, specifically includes the following steps:

[0040] S21: Input the topic information into a poetry prediction model to generate multiple candidate poems.

[0041] S22: Use the beam search method to predict the multiple candidate poems, and select candidate poems with a probability higher than a preset probability threshold from the multiple candidate poems as an initial candidate poem set.

[0042] Understandably, the poetry prediction model can be a deep learning (sequence2sequence) model. In the sequence2sequence model, the beam search method is only used in the test case (when the decoder is decoding), because during the training process, the output of each decoder has the correct answer, so there is no need for beam search to improve the accuracy of the output. Beam search is just a search strategy.

[0043] In this step, the terminal device pre-trains a poetry prediction model, inputs the subject information into the poetry prediction model, generates multiple candidate poems through the poetry prediction model, and then uses the beam search method to predict the multiple candidate poems, and selects candidate poems with a probability higher than a preset probability threshold from the multiple candidate poems as the initial candidate poetry set. The preset probability threshold refers to a probability value, and the preset probability threshold can be 0.8, 0.7, 0.6, etc. For example, the probability threshold of a candidate poem is 0.8, and the preset probability threshold is 0.6, then the candidate poem with a probability higher than the preset probability threshold is selected as the initial candidate poetry set.

[0044] exist Figure 3 In the corresponding embodiment, the beam search method is used to predict multiple candidate poems, and multiple candidate poems with high probability are selected as the initial candidate poem set, so that the selected candidate poems are the most likely poems to be the target poems, rather than unreasonable poems that are randomly output.

[0045] S30: Input the candidate poems in the initial candidate poem set into a preset n-gram language model to obtain a target candidate poem set.

[0046] In this step, the preset n-gram language model is a model used to calculate the probability of a sentence. The more a sentence conforms to the grammatical rules, the greater the probability.

[0047] In one embodiment, the initial candidate poetry set includes multiple candidate poems, such as Figure 4 As shown, in step S30, the candidate poems in the initial candidate poem set are input into a preset n-gram language model to generate a target candidate poem set, which specifically includes the following steps:

[0048] S31: Input the initial candidate poem set into the following Bayesian formula to calculate each candidate poem to obtain the probability of each candidate poem;

[0049] The Bayesian formula is:

[0050] p(w1w2...wn)=p(w1)*p(w2|w1)*p(w3|w1w2)....p(wn|w1w2w3...wn-1);

[0051] Among them, p(w1w2...wn) is the probability of each candidate poem; w1 is the first word; p(w1) is the probability of the first word; wn is the nth word; p(wn) is the probability of the nth word; p(wn|w1w2w3...wn-1) is the conditional probability of the following word wn appearing given that the previous word is w1w2w3...wn-1;

[0052] S32: sorting the probabilities of the plurality of candidate poems according to the rule of scores from large to small to obtain a probability sequence;

[0053] S33: In descending order of probability, select candidate poems whose probabilities exceed the preset fluency probability from the probability sequence as the target candidate poem set.

[0054] The Bayesian formula in the preset n-gram language model is used to calculate the probability of each candidate poem. It can be understood that for the language sequence w1, w2, w3, ... wn, the preset n-gram language model is to calculate the probability of the sequence, that is, P(w1, w2, w3, ..., wn). Among them, w1, w2, w3, ..., wn represent each word in the sentence. For example, if a sentence is "Sunset, east wind, spring grass is green", then w1 is "Sunset", w2 is "east wind", and w3 is "grass is green". The preset n-gram language model is used to determine whether a language sequence is a normal sentence. It can be considered that the probability P(w1, w2, w3, ..., wn) is the probability of whether this sentence is a normal poem. This step judges the fluency of the sentence through the probability obtained by the preset n-gram language model. The greater the probability, the better the fluency, and vice versa.

[0055] In this step, the initial candidate poem set is input into the following Bayesian formula to calculate each candidate poem, and the Bayesian formula is:

[0056] p(w1w2...wn)=p(w1)*p(w2|w1)*p(w3|w1w2)....p(wn|w1w2w3...wn-1);

[0057] Among them, p(w1w2...wn) is the probability of each candidate poem; w1 is the first word; p(w1) is the probability of the first word; wn is the nth word; p(wn) is the probability of the nth word; p(wn|w1w2w3...wn-1) is the conditional probability of the following word wn appearing given that the previous word is w1w2w3...wn-1.

[0058] After obtaining the probability of each candidate poem, the probabilities of the multiple candidate poems are sorted according to the rule of score from large to small to obtain a probability sequence; in order of probability from large to small, the candidate poems whose probabilities exceed the preset fluency probability are selected from the probability sequence as the target candidate poem set. It can be understood that the preset fluency probability refers to the probability of a pre-set fluency. For example, the preset fluency probability can be 0.6, 0.7 or 0.8, etc. For example, among the four candidate poems, the probability of the first candidate poem is 0.8, the probability of the second candidate poem is 0.2, the probability of the third candidate poem is 0.7, the probability of the fourth candidate poem is 0.5, and the preset fluency probability is 0.6. The probabilities of the four candidate poems are sorted according to the rule of score from large to small, and the probability sequence is 0.8, 0.7, 0.5, and 0.2. According to the order of probability from large to small, the candidate poems with a probability exceeding the preset fluency probability of 0.6 are selected from the probability sequence as the first candidate poem and the third candidate poem, and the first candidate poem and the third candidate poem are used as the target candidate poem set.

[0059] exist Figure 4 In the corresponding embodiment, each candidate poem is calculated to obtain the probability of each candidate poem, and candidate poems corresponding to the probability of candidate poems exceeding a preset quota are selected from the probability sequence as the target candidate poem set, thereby improving the fluency of the target poems generated subsequently.

[0060] S40: Performing rhyme screening on the candidate poems in the target candidate poetry collection according to preset rhyme rules to obtain a plurality of poems to be screened.

[0061] Understandably, the target candidate poetry collection is subjected to rhyme control according to preset rhyme rules, so that the target candidate poetry collection after rhyme screening has a rhyme effect.

[0062] In one embodiment, the preset rhyme rules include a first type of rhyme rule, a second type of rhyme rule, a third type of rhyme rule and a fourth type of rhyme rule, such as Figure 5 As shown, in step S40, that is, performing rhyme screening on the candidate poems in the target candidate poem set according to the preset rhyme rule to obtain multiple poems to be screened, specifically includes the following steps:

[0063] S41: Perform rhyme screening on the candidate poems in the target candidate poetry collection according to the first type of rhyme rule to obtain a first type of candidate poetry collection, wherein the first type of rhyme rule is a rule that the first sentence starts with a flat rhyme and does not rhyme.

[0064] In this step, the preset rhyme rules include any pre-set rules related to the rhyme rhythm of the poem. Preferably, the preset rhyme rules include predetermined level and oblique tones rules; the plurality of preset rhyme rules can be obtained in a variety of ways, for example, obtaining a plurality of predetermined level and oblique tones rules specified by a user. For example, the poetry type specified by the user is "seven-character quatrain", and four different types of preset rhyme rules corresponding to the poetry type are obtained.

[0065] Understandably, the target candidate poetry collection is screened for poetry rhyme according to the first type of rhyme rule to obtain the first type of candidate poetry collection, which is the target candidate poetry collection screened by the first type of rhyme rule; wherein the first type of rhyme rule is a rule that the first sentence starts with a flat rhyme and does not rhyme, specifically, the first type of rhyme rule may be: flat flat flat flat flat flat, flat ...

[0066] S42: Screening the candidate poems in the first category of candidate poetry collections for poetry rhyme according to the second type of rhyme rule to obtain the second category of candidate poetry collections, wherein the second type of rhyme rule is a rule of even-starting and first-sentence rhyme.

[0067] Understandably, the target candidate poetry collection filtered by the first type of rhyme rule is further screened for poetry rhyme according to the second type of rhyme rule to obtain the second type of candidate poetry collection, which is the target candidate poetry collection filtered by the second type of rhyme rule, wherein the second type of rhyme rule is a rule of starting with a flat rhyme and rhyming the first sentence. Specifically, the second type of rhyme rule can be: flat flat flat ze ze flat flat, ze ze flat flat ze ze flat. Ze ze flat flat ze ze, ze flat flat ze ze flat flat. For example, Wang Changling's "Out of the Frontier": The bright moon in Qin and the pass in Han, the people have not returned from the long march of thousands of miles. But if the flying general of Dragon City is here, the Hu horse will not be allowed to cross Yinshan.

[0068] S43: Perform poetry rhyme screening on the candidate poems in the second category of candidate poetry collection according to the third type of rhyme rule to obtain the third category of candidate poetry collection, wherein the third type of rhyme rule is a rule of starting with an unrhymed tone and the first sentence not rhyming.

[0069] Understandably, the target candidate poetry collection after the second type of rhyme rule is further screened for poetry rhyme according to the third type of rhyme rule to obtain the third type of candidate poetry collection, which is the target candidate poetry collection after the third type of rhyme rule is screened, wherein the third type of rhyme rule is a rule that the first sentence does not rhyme. Specifically, the third type of rhyme rule can be: Pingzezepingpingzeze, Zepingpingzezepingping. Pingpingpingzepingpingze, Pingzepingpingzezeping. For example, Wang Wei's "Remembering My Brothers in Shandong on the Ninth Day of the Ninth Month": Being a stranger in a foreign land, I miss my relatives even more during festivals. I know from afar that my brothers are climbing to a high place, and there is one less person wearing dogwood branches.

[0070] S44: Perform poetry rhyme screening on the candidate poems in the third category of candidate poetry collection according to the fourth type of rhyme rule to obtain the fourth category of candidate poetry collection, wherein the fourth type of rhyme rule is a rule of starting with an unlevel tone and rhyming the first sentence.

[0071] Understandably, the target candidate poetry collection after the third type of rhyme rule is further screened for poetry rhyme according to the fourth type of rhyme rule to obtain the fourth type of candidate poetry collection, which is the target candidate poetry collection after the fourth type of rhyme rule, wherein the fourth type of rhyme rule is a rule of starting with a flat tone and rhyming the first sentence. Specifically, the fourth type of rhyme rule can be flat flat flat flat flat flat flat. Flat flat flat flat flat flat flat flat flat flat. For example, Wang Changling's "Joining the Army": The long clouds of Qinghai darken the snow-capped mountains, and the lonely city looks at Yumen Pass in the distance. The yellow sand wears through the golden armor after a hundred battles, and I will never return until I have conquered Loulan!

[0072] S45: The candidate poems in the fourth category of candidate poetry set are used as the poems to be screened.

[0073] Understandably, the preset rhyme rules include first type rhyme rules, second type rhyme rules, third type rhyme rules and fourth type rhyme rules. The candidate poems in the fourth type of candidate poetry collection that have been screened by the first type rhyme rules, the second type rhyme rules, the third type rhyme rules and the fourth type rhyme rules are used as the target candidate poetry collection after rhyme screening. The target candidate poetry collection that has been screened by four types of rhyme rules has a certain improvement in rhyme.

[0074] exist Figure 5 In the corresponding embodiments, the target candidate poetry collection is screened for poetry rhyme according to the first type of rhyme rules, the second type of rhyme rules, the third type of rhyme rules and the fourth type of rhyme rules. Through multiple rhyme rules, the rhyme effect of the subsequently generated target poetry is controlled in terms of rhyme, thereby improving the poetry rhyme of the subsequently generated target poetry.

[0075] S50: Calculate the repetition rate of each poem to be screened.

[0076] In one embodiment, the poem to be screened is a complete poem, such as Figure 6 As shown, step S50, that is, calculating the repetition rate of each poem to be screened, specifically includes the following steps:

[0077] S51: Count the number of repeated words and the total number of words in the poems to be screened.

[0078] S52: Taking the ratio of the number of repeated words to the total number of words as the repetition rate.

[0079] It can be understood that the number of repeated words in each sentence of the poem to be screened, for example: the poem to be screened is "Yellow Crane Tower" by Cui Hao, "The ancients have gone away on the yellow crane, leaving only the Yellow Crane Tower. The yellow crane has gone and will never return, and the white clouds have been floating in the sky for thousands of years. The clear river reveals the trees of Hanyang, and the fragrant grass covers the Parrot Island. Where is my hometown at dusk? The misty river makes me sad." Among them, the number of repeated words in the first sentence of the poem to be screened is 0, the number of repeated words in the second sentence is 2, the number of repeated words in the third sentence is 4, and the number of repeated words in the fourth sentence is 0. The total number of words in the poem to be screened is 6, and the total number of words in the poem to be screened is 56. Therefore, the ratio of the number of repeated words in the poem to be screened to the total number of words in the poem to be screened is: 6 / 56=0.107, that is, the repetition rate is 0.107.

[0080] exist Figure 6 In the corresponding embodiment, the ratio of the number of repeated words in the poems to be screened to the total number of words in the poems to be screened is used as the repetition rate, and the number of repeated words in the poems to be screened and the total number of words in the poems to be screened are used as calculation parameters. The repetition rate is calculated through specific calculation parameters, which improves the accuracy of the repetition rate calculation and improves the non-repetitiveness of the target poems generated subsequently.

[0081] S60: Screening the repetition rates of multiple poems to be screened according to the repetition rates to obtain target poems.

[0082] In one embodiment, if Figure 7 As shown, in step S60, that is, the repetition rate of multiple poems to be screened is screened according to the repetition rate to obtain the target poem, which specifically includes the following steps:

[0083] S61: Compare the preset threshold with the repetition rate of the poem to be screened.

[0084] S62: If the repetition rate of the poems to be screened is less than a preset threshold, the poems to be screened corresponding to the repetition rate less than the preset threshold are taken as target poems.

[0085] It can be understood that the preset threshold is a preset value, for example, the preset threshold is 0.3, 0.2 or 0.1, etc., which is not limited in this specific scheme; if the preset threshold is 0.2, the preset threshold 0.2 is compared with the repetition rate of 0.107 of the poems to be screened, and the result is that the repetition rate of the poems to be screened is less than the preset threshold, and the poems to be screened corresponding to the repetition rate less than the preset threshold are taken as target poems.

[0086] exist Figure 7 In the corresponding embodiment, the to-be-screened poems corresponding to the repetition rate exceeding the preset threshold are taken as the target poems, and the non-repetitiveness of the subsequently generated target poems is controlled based on the repetition rate, thereby ensuring that the subsequently generated target poems have fewer repeated words, thereby improving the non-repetitiveness of the subsequently generated target poems.

[0087] exist Figure 2 In the corresponding embodiment, the candidate poems are input into a preset n-gram language model for poetry fluency screening, and the target candidate poetry set is screened for poetry rhyme according to preset rhyme rules, and the poetry repetition rate of multiple poems to be screened is screened according to the repetition rate. The initial candidate poetry set predicted by the beam search method is screened by poetry fluency, poetry rhyme and poetry repetition rate, thereby improving the fluency, rhyme and non-repetitiveness of the generated poems.

[0088] In one embodiment, if Figure 8 As shown, before step S10, that is, before obtaining the subject information of the poem to be generated, the following steps are specifically included:

[0089] S71: Acquire general domain data, wherein the general domain data includes five-character quatrains, seven-character quatrains, news, hypertext data, and question-and-answer data.

[0090] S72: Using the general domain data as a pre-training data set.

[0091] S73: Using the pre-training data set to train a preset n-gram language model.

[0092] In this step, the domain data includes five-character quatrains, seven-character quatrains, news, hypertext data, question-answering data, five-character regulated verses, seven-character regulated verses, and ci tune names, etc. The general domain data is used as a pre-training data set to train a preset n-gram language model using the SRILM open source toolkit.

[0093] Understandably, the preset n-gram language model is trained using the SRILM open source toolkit, which is an open source toolkit for building and using statistical preset n-gram language models, to facilitate training and application of the preset n-gram language model.

[0094] exist Figure 8 In the corresponding embodiment, general domain data is used as a pre-training data set, and the training set of the preset n-gram language model is much larger than the training set for poetry generation. It is not only poetry data, but also other news, hypertext data, question-and-answer data, etc. The preset n-gram language model is an unsupervised data, which solves the problem that the training set for poetry generation must consist of keywords and a line of poetry, resulting in a very small training set; the preset n-gram language model that is trained separately solves the problem of inconsistency between model training and model prediction, and the generated poetry is more fluent.

[0095] It should be understood that the order of execution of the steps in the above embodiments does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the present invention.

[0096] In one embodiment, a poetry generation device is provided, which corresponds one-to-one to the poetry generation method in the above embodiment. Fig. 9 As shown, the poetry generation device includes an acquisition module 10, a generation module 20, a fluency screening module 30, a rhyme screening module 40, a calculation module 50 and a repetition rate screening module 60. The functional modules are described in detail as follows:

[0097] An acquisition module 10 is used to acquire the subject information of the poem to be generated;

[0098] A generation module 20, inputting the subject information into a poetry prediction model to generate an initial candidate poetry set;

[0099] Fluency screening module 30, inputting candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set;

[0100] A rhyme screening module 40 performs rhyme screening on the candidate poems in the target candidate poem set according to a preset rhyme rule to obtain a plurality of poems to be screened;

[0101] A calculation module 50 calculates the repetition rate of each poem to be screened;

[0102] The repetition rate screening module 60 screens the repetition rate of multiple poems to be screened according to the repetition rate to obtain the target poem.

[0103] The rhyme screening module 40 is specifically used for:

[0104] Performing rhyme screening on the candidate poems in the target candidate poetry collection according to a first type of rhyme rule to obtain a first type of candidate poetry collection, wherein the first type of rhyme rule is a rule that the first sentence does not rhyme;

[0105] The candidate poems in the first category of candidate poetry collections are screened for poetry rhyme according to a second type of rhyme rule to obtain a second category of candidate poetry collections, wherein the second type of rhyme rule is a rule that the first sentence of a poem starts flat and rhymes;

[0106] The candidate poems in the second category of candidate poems are screened for rhyme according to the third type of rhyme rule to obtain the third category of candidate poems, wherein the third type of rhyme rule is a rule of starting with an unrhymed first sentence;

[0107] The candidate poems in the third category of candidate poetry collections are screened for poetry rhyme according to the fourth type of rhyme rule to obtain the fourth category of candidate poetry collections, wherein the fourth type of rhyme rule is a rule of starting with an unsteady tone and rhyming the first sentence;

[0108] The candidate poems in the fourth category of candidate poetry collection are used as the poems to be screened.

[0109] The calculation module 50 is specifically used for:

[0110] Count the number of repeated words and the total number of words in the poems to be screened;

[0111] The ratio of the number of repeated words to the total number of words is taken as the repetition rate.

[0112] The repetition rate screening module 60 is specifically used for:

[0113] Comparing the preset threshold with the repetition rate of each poem to be screened;

[0114] If the repetition rate in the poems to be screened is less than a preset threshold, the poems to be screened corresponding to the repetition rate less than the preset threshold are taken as target poems.

[0115] The fluency screening module 30 is specifically used for:

[0116] Input the initial candidate poem set into the following Bayesian formula to calculate each candidate poem to obtain the probability of each candidate poem;

[0117] The Bayesian formula is:

[0118] p(w1w2...wn)=p(w1)*p(w2|w1)*p(w3|w1w2)....p(wn|w1w2w3...wn-1);

[0119] Among them, p(w1w2...wn) is the probability of each candidate poem; w1 is the first word; p(w1) is the probability of the first word; wn is the nth word; p(wn) is the probability of the nth word; p(wn|w1w2w3...wn-1) is the conditional probability of the following word wn appearing given that the previous word is w1w2w3...wn-1;

[0120] According to the rule of descending scores, the probabilities of the plurality of candidate poems are sorted to obtain a probability sequence;

[0121] In descending order of probability, candidate poems whose probabilities exceed the preset fluency probability are selected from the probability sequence as the target candidate poem set.

[0122] The poetry generation device also includes a preset n-gram language model training module, which is specifically used for:

[0123] Acquire general domain data, wherein the general domain data includes five-character quatrains, seven-character quatrains, news, hypertext data, and question-and-answer data;

[0124] Using the general domain data as a pre-training dataset;

[0125] The pre-training data set is used to train a preset n-gram language model.

[0126] The generating module 20 is specifically used for:

[0127] Inputting the topic information into a poetry prediction model to generate multiple candidate poems;

[0128] The beam search method is used to predict the poems of the plurality of candidate poems, and the candidate poems with probability higher than a preset threshold are selected from the plurality of candidate poems as the initial candidate poem set.

[0129] For the specific limitations of the poetry generation device, please refer to the limitations of the poetry generation method above, which will not be repeated here. Each module in the above-mentioned poetry generation device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0130] In one embodiment, Fig.10 As shown, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented:

[0131] Obtain the subject information of the poem to be generated;

[0132] Inputting the topic information into a poetry prediction model to generate an initial candidate poetry set;

[0133] Input the candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set;

[0134] Performing rhyme screening on the candidate poems in the target candidate poetry set according to a preset rhyme rule to obtain a plurality of poems to be screened;

[0135] Calculate the repetition rate of each poem to be screened;

[0136] The repetition rates of multiple poems to be screened are screened according to the repetition rates to obtain target poems.

[0137] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0138] Obtain the subject information of the poem to be generated;

[0139] Inputting the topic information into a poetry prediction model to generate an initial candidate poetry set;

[0140] Input the candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set;

[0141] Performing rhyme screening on the candidate poems in the target candidate poetry set according to a preset rhyme rule to obtain a plurality of poems to be screened;

[0142] Calculate the repetition rate of each poem to be screened;

[0143] The repetition rates of multiple poems to be screened are screened according to the repetition rates to obtain target poems.

[0144] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0145] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0146] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A poetry generation method, characterized in that: include: Obtain the subject information of the poem to be generated; Inputting the topic information into a poetry prediction model to generate an initial candidate poetry set; Input the candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set; Performing rhyme screening on the candidate poems in the target candidate poetry set according to a preset rhyme rule to obtain a plurality of poems to be screened; Calculate the repetition rate of each poem to be screened; Screening the multiple poems for repetition rate according to the repetition rate to obtain the target poem; The step of inputting candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set includes: Input the initial candidate poem set into the following Bayesian formula to calculate each candidate poem to obtain the probability of each candidate poem; The Bayesian formula is: p(w1w2...wn)=p(w1)*p(w2|w1)*p(w3|w1w2)....p(wn|w1w2w3...wn-1); Among them, p(w1w2...wn) is the probability of each candidate poem; w1 is the first word; p(w1) is the probability of the first word; wn is the nth word; p(wn) is the probability of the nth word; p(wn|w1w2w3...wn-1) is the conditional probability of the following word wn appearing given that the previous word is w1w2w3...wn-1; According to the rule of descending scores, the probabilities of the plurality of candidate poems are sorted to obtain a probability sequence; In descending order of probability, selecting candidate poems whose probabilities exceed a preset fluency probability from the probability sequence as a target candidate poem set; The step of calculating the repetition rate of each poem to be screened includes: Count the number of repeated words and the total number of words in the poem to be screened; The ratio of the number of repeated words to the total number of words is taken as the repetition rate.

2. The poetry generation method according to claim 1, characterized in that: The method of screening the repetition rate of multiple poems to be screened according to the repetition rate to obtain a target poem includes: Comparing the preset threshold with the repetition rate of each poem to be screened; If the repetition rate in the poems to be screened is less than a preset threshold, the poems to be screened corresponding to the repetition rate less than the preset threshold are taken as target poems.

3. The poetry generation method according to claim 1, characterized in that: Before obtaining the subject information of the poem to be generated, the method further includes: Acquire general domain data, wherein the general domain data includes five-character quatrains, seven-character quatrains, news, hypertext data, and question-and-answer data; Using the general domain data as a pre-training dataset; The preset n-gram language model is trained using the pre-training data set.

4. The poetry generation method according to claim 1, characterized in that: The step of inputting the topic information into a poetry prediction model to generate an initial candidate poetry set includes: Inputting the topic information into a poetry prediction model to generate multiple candidate poems; The beamsearch method is used to predict the poems of the plurality of candidate poems, and the candidate poems with probability higher than a preset threshold are selected from the plurality of candidate poems as the initial candidate poem set.

5. A poetry generation device, characterized in that: include: An acquisition module is used to obtain the theme information of the poem to be generated; A generation module, inputting the subject information into a poetry prediction model to generate an initial candidate poetry set; The fluency screening module inputs the candidate poems in the initial candidate poem set into a preset n-gram language model to generate a target candidate poem set; A rhyme screening module performs rhyme screening on the candidate poems in the target candidate poem set according to preset rhyme rules to obtain multiple poems to be screened; A calculation module, calculating the repetition rate of each poem to be screened; A repetition rate screening module, screening the repetition rates of multiple poems to be screened according to the repetition rate to obtain a target poem; The fluency screening module is specifically used for: Input the initial candidate poem set into the following Bayesian formula to calculate each candidate poem to obtain the probability of each candidate poem; The Bayesian formula is: p(w1w2...wn)=p(w1)*p(w2|w1)*p(w3|w1w2)....p(wn|w1w2w3...wn-1); Among them, p(w1w2...wn) is the probability of each candidate poem; w1 is the first word; p(w1) is the probability of the first word; wn is the nth word; p(wn) is the probability of the nth word; p(wn|w1w2w3...wn-1) is the conditional probability of the following word wn appearing given that the previous word is w1w2w3...wn-1; According to the rule of descending scores, the probabilities of the plurality of candidate poems are sorted to obtain a probability sequence; In descending order of probability, selecting candidate poems whose probabilities exceed a preset fluency probability from the probability sequence as a target candidate poem set; Computing module, specifically used for: Count the number of repeated words and the total number of words in the poem to be screened; The ratio of the number of repeated words to the total number of words is taken as the repetition rate.

6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the poem generation method as described in any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the poetry generation method as described in any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Method and device for automatically generating poems

    CN106095752A

  • Deep learning-based poetry generation method and device, apparatus, and storage medium

    CN110134968A