A method and apparatus for automatic couplet generation based on deep learning

By constructing a deep learning seq2seq model and combining it with corpora of couplets and classical poems, a multi-strategy enhancement method was adopted to solve the problems of insufficient parallelism and fluency in couplet generation. This achieved bidirectional generation and quality improvement of couplets, resulting in more diverse and parallel couplets.

CN116362232BActive Publication Date: 2026-04-03TSINGHUA UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-29
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

Existing couplet generation technologies are insufficient in terms of parallelism, fluency, and novelty, making it difficult to generate an upper couplet from a lower couplet and vice versa. Furthermore, the generated couplets are of poor quality, monotonous in content, and cannot effectively utilize deep learning models to improve the generation quality.

Method used

A deep learning-based seq2seq model is constructed, combining couplet corpora and ancient poetry corpora. It is trained using the Teacher Forcing mechanism. Through topic embedding encoding, length encoding, generation direction encoding, and genre type encoding, a loss function is constructed to generate a candidate word probability distribution function. High-frequency randomized kernel sampling and antithesis judgment model are used to achieve bidirectional generation and multi-strategy enhancement of couplets.

Benefits of technology

It improves the fluency, parallelism, and novelty of couplet generation, and realizes the generation of "upper line from lower line" and "lower line from upper line". The quality of generated couplets is significantly improved, and they have greater diversity and inspiration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116362232B_ABST
    Figure CN116362232B_ABST
Patent Text Reader

Abstract

This invention provides a method and apparatus for automatic couplet generation based on deep learning, comprising: inputting pre-encoded target upper couplet / target lower couplet into a seq2seq model to obtain the candidate word probability distribution function for each word segment in the pre-generated lower couplet / upper couplet; generating multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function; selecting the optimal lower couplet / upper couplet from the multiple sets of candidate lower couplets / upper couplets through a scoring method; and combining the optimal lower couplet / upper couplet with the target upper couplet / target lower couplet to obtain a parallel couplet. This invention utilizes a seq2seq model, which performs well in terms of couplet generation fluency, parallelism, and novelty, a high-frequency randomized kernel sampling method, and optimal selection to achieve multi-strategy enhanced generation of couplets, thereby improving the quality of couplet generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to a method and apparatus for automatically generating couplets based on deep learning. Background Technology

[0002] Couplets are an important carrier of Chinese culture, possessing the quality of being appreciated by both the refined and the common people, and are also an important national cultural heritage. With the rise of artificial intelligence, intelligent couplet generation technology has also emerged. However, although couplets only consist of two lines, they are subject to many restrictions on the number of characters, semantics, syntax, and tonal patterns, which greatly increases the difficulty of creating novel and parallel couplets.

[0003] Currently, most couplet generation methods employ RNNs, Transformers, and other couplet generation models, along with hard-coded couplet evaluators. However, this approach has the following drawbacks:

[0004] (1): It does not perform well in terms of parallelism and fluency, and requires manual selection of usable couplets from the generated couplets;

[0005] (2): The generated couplets are relatively monotonous in terms of word choice and sentence structure, with a large number of high-frequency word pairs being used, and the content of the upper and lower lines being quite similar, resulting in poor couplet quality and difficulty in providing inspiration for manual writing.

[0006] (3) Couplet generation is usually limited to “matching the first line with the second line” and cannot achieve “matching the second line with the first line”. Summary of the Invention

[0007] To solve or partially solve the above problems, this invention provides a method and apparatus for automatically generating couplets based on deep learning. By constructing a seq2seq model that performs well in terms of couplet fluency, parallelism, and novelty, it can generate an upper couplet from a lower couplet and a lower couplet from an upper couplet. Given an upper / lower couplet, it can generate each sub-couplet corresponding to the lower / upper couplet.

[0008] The candidate word probability distribution function is generated, and then a high-frequency randomized kernel sampling method is used to generate multiple sets of candidate lower / upper lines based on the candidate word probability distribution function. Finally, the results are scored.

[0009] The optimal lower / upper line is selected by prioritizing the best options, and the quality of couplet generation is improved through multiple enhanced strategies.

[0010] In a first aspect, the present invention provides a method for automatically generating couplets based on deep learning, the method comprising:

[0011] 0. Pre-encode the target upper / lower line;

[0012] The pre-encoded target upper / lower line is input into the seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower / upper line corresponding to the target upper / lower line;

[0013] Based on the candidate word probability distribution function of each word segment, a high-frequency randomized kernel 5 sampling method is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet; the optimal lower couplet / upper couplet is selected from the multiple sets of candidate lower couplets / upper couplets by scoring, and the optimal lower couplet / upper couplet and the target upper couplet / target lower couplet are combined to obtain a parallel couplet;

[0014] The seq2seq model is a bidirectional generation model for couplets trained using the TeacherForcing mechanism, based on the corpus of couplets and ancient poems.

[0015] According to the deep learning-based automatic couplet generation method provided by the present invention, the precoding includes, but is not limited to: topic embedding encoding, length encoding, generation direction encoding, and genre type encoding;

[0016] The generated direction encoding includes: encoding the direction label PRED-LO or 5PRED-UP;

[0017] The genre type encoding includes: encoding the genre label IS-CPLT or NOT-CPLT; the PRED-LO characterizes the generation of a lower line given an upper line;

[0018] The PRED-UP characterizes the generation of an upper couplet given a lower couplet.

[0019] The IS-CPLT characterization has a requirement for parallelism;

[0020] The NOT-CPLT characterization indicates that there is no need for symmetry.

[0021] According to the deep learning-based automatic couplet generation method provided by the present invention, the step of performing topic embedding encoding on the target upper line / target lower line includes:

[0022] Using a pre-built topic model, infer the topic of the target upper / lower line; encode the topic for the target upper / lower line;

[0023] The process of constructing the topic model includes:

[0024] Each first line of the couplet corpus, each second line of the couplet corpus, and each sentence of the ancient poetry corpus are treated as a single document;

[0025] Perform word segmentation on each document;

[0026] By using word distribution to represent topics and topic distribution to represent documents, a topic model is constructed that applies to all documents.

[0027] According to the deep learning-based automatic couplet generation method provided by the present invention, the construction process of the 5seq2seq model includes:

[0028] Each pair of poems in the ancient poetry corpus is treated as a special couplet and added to the couplet corpus to broaden the couplet corpus;

[0029] The upper and lower lines of each couplet in the expanded couplet corpus are pre-edited separately.

[0030] The code yields 0 samples with the pre-encoded upper line as the given line and the pre-encoded lower line as the target line, and samples with the pre-encoded lower line as the original line and the pre-encoded upper line as the target line.

[0031] sample;

[0032] Generate a first dataset containing all samples;

[0033] A loss function is constructed based on preset antithetical couplet rules;

[0034] Using the given linker in each sample of the first dataset as the input to the encoder, and the noise variant of the target linker in each sample of the first dataset as the input to the decoder, the following is achieved:

[0035] Training a seq2seq model based on the loss function.

[0036] According to the deep learning-based automatic couplet generation method provided by the present invention, x = {x1, x2, ... x} n} represents a given connection, where y = {y1, y2, ... y} n} represents the condition based on x = {x1, x2, ... x} n The corresponding single link generated;

[0037] The preset antithetical couplet rules include, but are not limited to:

[0038] exist When y is not an empty set, t Do not take word segmentation in Chinese;

[0039] exist When y is not an empty set, t Pick word segmentation in Chinese;

[0040] exist When y is not an empty set, t Do not take word segmentation in Chinese;

[0041] Where, x t Let x = {x1, x2, ... x} n The t-th word in}, y t Let y = {y1, y2, ... y n The t-th word in}.

[0042] According to the deep learning-based automatic couplet generation method provided by the present invention, the loss function... The expression is as follows:

[0043]

[0044] In the above formula, C t ={x1,x2,…x t-1}, where θ is the parameter of the seq2seq model, α1 is the weight of the first hyperparameter, α2 is the weight of the second hyperparameter, α3 is the weight of the third hyperparameter, α4 is the weight of the fourth hyperparameter, and y is the weight of the fourth hyperparameter. <t For the sequence {y1,y2,…y} t-1}, p θ (y t |x,y <t ) is when x and y <t Given the premise that each y exists t The probability of occurrence, p θ (y t |x <t ) is when x <t Given the premise that each y exists t The probability of occurrence;

[0045] Let x = {x1, x2, ... x} n} represents a given connection, with y true ={y true,1 ,y true,2 ,…y true,n} represents the relationship between x = {x1, x2, ... x} n The target group in the same sample, y true ={y true,1 ,y true,2 ,…y true,n The noise variant of} is y noise ={y noise,1 ,y noise,2 ,…y noise,n};

[0046] Among them, y noise The t-th word y noise,t The expression is as follows:

[0047]

[0048] In the above formula, y true,t For y ture The t-th word, α5 is the weight of the fifth hyperparameter, C β For y t The candidate word set, y j C β For any j-th candidate word, p θ (y t =y β |x,y <t ) is when x and y <t Given that y exists, t For y j The probability of.

[0049] According to the deep learning-based automatic couplet generation method provided by the present invention, the step of generating multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function of each word segment includes:

[0050] For each word segmentation candidate word probability distribution function, sort each candidate word in the candidate word probability distribution function in descending order of probability;

[0051] Starting from the first candidate word in the sorted sequence, calculate the cumulative probability at each candidate word in the sorted sequence;

[0052] Candidate words in the sorted sequence whose cumulative probability does not exceed the first cumulative probability threshold are assigned to area H; candidate words in the sorted sequence whose cumulative probability exceeds the first cumulative probability threshold but does not exceed the second cumulative probability threshold, whose sorting number does not exceed the sorting threshold, or whose own probability does not exceed the probability threshold are assigned to area M; and candidate words in the sorted sequence other than those in areas H and M are assigned to area L.

[0053] Delete all candidate words in region L, distribute the cumulative probabilities of all candidate words in region L to candidate words in regions H and M proportionally, and correct the probability of each candidate word in region H to the ratio of the cumulative probability of all candidate words in region H to the number of candidate words in region H, so as to update the candidate word probability distribution function.

[0054] Randomly sample and combine the probability distribution functions of all candidate words after word segmentation update to obtain multiple sets of alternative lower / upper lines corresponding to the target upper / lower line.

[0055] According to the deep learning-based automatic couplet generation method provided by the present invention, the step of selecting the optimal lower / upper line from the multiple sets of candidate lower / upper lines through a scoring method includes:

[0056] Delete any candidate lower or upper couplets from the multiple sets of candidate lower / upper couplets that do not conform to the preset antithetical couplet rules;

[0057] Substitute the remaining candidate lower / upper lines into the pre-built antithesis judgment model to obtain the scores of the remaining candidate lower / upper lines;

[0058] The candidate lower / upper line that simultaneously satisfies the condition of having the highest score and a score greater than a preset score threshold will be selected as the optimal lower / upper line.

[0059] According to the deep learning-based automatic couplet generation method provided by the present invention, the construction process of the antithesis judgment model includes:

[0060] Using the aforementioned couplet corpus and a preset negative example construction method, a multi-granularity hybrid negative example dataset is constructed.

[0061] Using the couplet corpus as a positive example dataset, a multi-granularity mixed antithesis judgment dataset is generated, which includes the couplet corpus and the multi-granularity mixed negative example dataset.

[0062] A linear classifier layer is added to the BERT model pre-trained on a corpus of classical poetry to obtain the initial model architecture;

[0063] The initial model architecture is fine-tuned using the multi-granularity hybrid antithesis judgment dataset to obtain the antithesis judgment model;

[0064] The construction of a multi-granularity hybrid negative example dataset using the couplet corpus and a preset negative example construction method includes:

[0065] Randomly select any word in the second line of each couplet in the couplet corpus, and replace the random word with a word whose character frequency ranking in the character set is similar to the random word to obtain corresponding negative sample samples;

[0066] and / or

[0067] Randomly select any word from the second line of each couplet in the couplet corpus. Input the first line of each couplet in the couplet corpus into the encoder of the seq2seq model. Input the word segment before the random word from the second line of each couplet in the couplet corpus into the decoder of the seq2seq model to obtain the probability distribution of candidate words corresponding to the random word. Select candidate words with low probability and high frequency in the character set from the probability distribution of candidate words corresponding to the random word to replace the random word, so as to obtain the corresponding negative sample.

[0068] and / or

[0069] From the couplet corpus, randomly select several word segments from the second line of each couplet and randomly swap their positions to obtain corresponding negative sample samples;

[0070] and / or

[0071] The second line of each couplet in the corpus is randomly replaced with another second line of equal length to obtain negative sample samples.

[0072] Secondly, the present invention provides a deep learning-based automatic couplet generation device, the device comprising:

[0073] The precoding module is used to precode the target upper / lower line;

[0074] The determination module is used to input the pre-encoded target upper line / target lower line into the seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower line / upper line corresponding to the target upper line / target lower line;

[0075] The generation module is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet by using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function of each word segment;

[0076] The optimization module is used to select the optimal lower / upper line from the multiple sets of candidate lower / upper lines by scoring, and to combine the optimal lower / upper line and the target upper / lower line to obtain a parallel couplet;

[0077] The seq2seq model is a bidirectional generation model for couplets, trained using the TeacherForcing mechanism based on couplet corpora and ancient poetry corpora.

[0078] This invention provides a deep learning-based method and apparatus for automatically generating couplets. It pre-constructs a seq2seq model that performs well in terms of fluency, parallelism, and novelty, enabling both "generating an upper couplet from a lower couplet" and "generating a lower couplet from an upper couplet." Then, the seq2seq model is used to generate a candidate word probability distribution function for each word segment in a given target upper couplet / corresponding lower couplet / upper couplet. Next, based on this candidate word probability distribution function, a high-frequency randomized kernel sampling method is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / corresponding lower couplet. Finally, a scoring-based selection method is used to select the optimal lower couplet / upper couplet, which is then combined with the target upper couplet / corresponding lower couplet to obtain a parallel couplet. This invention enables bidirectional couplet generation and improves the quality of couplet generation based on multi-strategy enhancement. Attached Figure Description

[0079] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0080] Figure 1 This is a flowchart illustrating the deep learning-based automatic couplet generation method provided by the present invention.

[0081] Figure 2 This is a comparison chart of the candidate word probability distribution function before and after the update provided by this invention;

[0082] Figure 3 This is a schematic diagram of the structure of the deep learning-based automatic couplet generation device provided by the present invention;

[0083] Figure 4 This is a schematic diagram of the structure of an electronic device that implements a deep learning-based automatic couplet generation method provided by the present invention.

[0084] Figure label:

[0085] 410: Processor; 420: Communication interface; 430: Memory; 440: Communication bus. Detailed Implementation

[0086] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0087] The following is combined Figures 1-4 This invention describes a deep learning-based method and apparatus for automatically generating couplets.

[0088] Firstly, generally speaking, people have the following quality requirements for couplets: In terms of form, they require grammar and syntax to be consistent, and the text to be fluent and smooth while also meeting the rules of parallelism; in terms of meaning, they require rich semantic information within sentences, novel word choice and sentence structure, and related and connected meanings between sentences without being too similar. Early research on couplet generation used rule matching and other methods to generate couplets. With the development of deep learning, neural networks have gradually been introduced into couplet generation tasks, especially seq2seq models with an encoder-decoder structure. However, in the field of couplet generation, most use RNN, Transformer and other couplet generation models and hard-coded couplet evaluators to achieve couplet generation. The couplets generated by these methods are insufficient in terms of fluency, parallelism and novelty. At the same time, couplets must conform to the rule of "rising tone at the beginning and falling tone at the end," that is, the first line ends with a falling tone and the second line ends with a falling tone. The above couplet generation is a "matching the first line with the second line" mode, which cannot handle inputs ending in a falling tone and cannot achieve "matching the second line with the first line."

[0089] To this end, the present invention pre-constructs a seq2seq model; wherein, the seq2seq model is a bidirectional generation model of upper and lower couplets trained by the Teacher Forcing mechanism on the basis of couplet corpus and ancient poetry corpus.

[0090] The couplet corpus is a database containing numerous couplets, and the classical poetry corpus is a database containing numerous poems with consecutive lines. Examples of such poems include: "Painting is unaware of approaching old age, wealth and honor are like fleeting clouds to me"; "The road is long and the soul flies in anguish, my dreams cannot reach the distant mountains"; "A thousand sails pass by the sunken ship, ten thousand trees bloom before the withered tree".

[0091] Specifically, the construction process of a seq2seq model includes:

[0092] Step A: Topic Model Construction;

[0093] The process of constructing a topic model is as follows:

[0094] Step A-1, word segmentation;

[0095] In order to capture the internal connections of phrases in the couplet corpus and the classical poetry corpus (which can only be replaced by other Chinese corpus), each first line of the couplet corpus, each second line of the couplet corpus, and each sentence of the classical poetry corpus are treated as a document;

[0096] The unsupervised word segmentation algorithm BPE (Byte Pair Encoding) is used to segment each of the above documents.

[0097] Step A-2: Topic Modeling:

[0098] By using word distribution to represent topics and topic distribution to represent documents, a topic model is constructed that applies to all documents. This topic model is a three-level hierarchical Bayesian model constructed using LDA (Latent Dirichlet Allocation).

[0099] Step B: Couplet precoding:

[0100] Step B-1: Treat each pair of upper and lower lines of poetry in the ancient poetry corpus as a special couplet and add it to the couplet corpus to broaden the couplet corpus;

[0101] Step B-2: Pre-encode the first and second lines of each couplet in the augmented couplet corpus.

[0102] Specifically, precoding includes, but is not limited to: topic embedding encoding, length encoding, generation direction encoding, and genre type encoding;

[0103] For topic embedding encoding:

[0104] This involves using the topic model constructed in step A to infer the topic of the target single line (the upper or lower line of a couplet) and adding a corresponding topic tag TOPIC-s (where s is the topic number) to the target single line.

[0105] Topic embedding encoding can help seq2seq models learn the topic transformation process and provide them with the ability to generate controllable topics based on topic tags.

[0106] For length encoding:

[0107] This involves adding a length tag LEN-k (where k is the length) to the target single line, indicating the length of the pre-generated single line for the target single line, thereby ensuring that the number of characters in the upper and lower lines of the generated couplet are equal.

[0108] For generating directional encoding:

[0109] The seq2seq model aims to achieve bidirectional generation of couplets using the same set of parameters, thereby solving the problem of "generating the first line for the second line" and allowing the model's encoder and decoder to obtain information from the training corpus of the two lines (instead of the first line corpus in the traditional training method) during the training process.

[0110] Therefore, two directional labels, PRED-LO (representing the generation of a lower couplet given an upper couplet) and PRED-UP (representing the generation of an upper couplet given a lower couplet), were added to indicate the direction of couplet generation.

[0111] For genre type encoding:

[0112] Introducing ancient poems and phrases with semantic similarities to couplets into couplet generation provides more semantic information for the seq2seq model.

[0113] To ensure that the seq2seq model does not forget the knowledge of parallelism while expanding semantics, two genre labels, IS-CPLT (representing that there is a need for parallelism) and NOT-CPLT (representing that there is no need for parallelism), are added to ensure the parallelism of the generated couplets.

[0114] During encoding, the genre label corresponding to the upper and lower lines of poetry is identified as NOT-CPLT, and the genre label corresponding to couplets is identified as IS-CPLT.

[0115] Step C: Construct the first dataset for training the seq2seq model:

[0116] Step C-1: For each couplet in the augmented couplet corpus, take a sample with the pre-encoded first line as the given couplet and the pre-encoded second line as the target couplet, and a sample with the pre-encoded second line as the original couplet and the pre-encoded first line as the target couplet.

[0117] Step C-2; Generate the first dataset containing all samples;

[0118] Step D: Construct a loss function based on preset antithetical couplet rules;

[0119] Seq2seq models typically construct a loss function based on maximum likelihood estimation and are trained using Teacher Forcing.

[0120] That is, let x = {x1, x2, ... x} n} represents a given connection, where y = {y1, y2, ... y} n} represents the condition based on x = {x1, x2, ... x} n The corresponding generated single link aims to maximize the likelihood objective P(y). t |x,y <t The loss function is

[0121] L(p θ (·|x,y <t ))=-logp θ (y t |x,y <t )

[0122] By adding nonlikelihood training loss to the loss function, the probability of the model generating words that have already appeared can be reduced, thus alleviating the monotonicity problem of text generation.

[0123] Remember C t ={x1,x2,…x t-1}, then the nonlikelihood training loss is defined as:

[0124]

[0125] After adding the hyperparameter weight α1, the loss function is correspondingly adjusted to:

[0126]

[0127] Due to the unique language rules of couplets, at y t the following three sets can be constructed according to the couplet rules:

[0128]

[0129]

[0130]

[0131] For example, for the couplet "Upper couplet: Wangjiang Tower, overlooking the river flow, overlooking the river flow under the Wangjiang Tower, the river tower lasts forever, the river flow lasts forever; Lower couplet: Printing Moon Well, printing the moon shadow, printing the moon shadow in the Printing Moon Well, the moon well lasts for ten thousand years, the moon shadow lasts for ten thousand years", when generating the character "well" in "printing the moon shadow in the Printing Moon Well", the three sets constructed are:

[0132]

[0133]

[0134]

[0135] y t needs to satisfy:

[0136] At when it is not an empty set, y t does not take the word segmentation in;

[0137] At when it is not an empty set, y t takes the word segmentation in;

[0138] At when it is not an empty set, y t does not take the word segmentation in;

[0139] Among them, x t is the t-th word segmentation in x = {x1, x2,... x n}, and y t is the t-th word segmentation in y = {y1, y2,... y n}.

[0140] According to the rules of antithesis in couplets, we should penalize the set during generation. and Rewards Collection Therefore, the loss function is adjusted to...

[0141]

[0142] In the above formula, C t ={x1,x2,…x t-1}, where θ is the parameter of the seq2seq model, α1 is the weight of the first hyperparameter, α2 is the weight of the second hyperparameter, α3 is the weight of the third hyperparameter, α4 is the weight of the fourth hyperparameter, and y is the weight of the fourth hyperparameter. <t For the sequence {y1,y2,…y} t-t}, x <t For the sequence {x1, x2, ... x t-1},p θ (y t |x,y <t ) is when x and y <t Given the premise that each y exists t The probability of occurrence, p θ (y t |x <t ) is when x <t Given the premise that each y exists t The probability of occurrence.

[0143] Step E: Train the seq2seq model;

[0144] The given linker in each sample of the first dataset is used as the input to the encoder, and the noise variant of the target linker in each sample of the first dataset is used as the input to the decoder, thereby enabling the training of a seq2seq model based on the loss function.

[0145] The initial architecture of the seq2seq model uses the Transformer model, with x = {x1, x2, ... x}. n} represents a given connection, with y true ={y true,1 ,y true,2 ,…y true,n} represents the relationship between x = {x1, x2, ... x} n For targets in the same sample, during training, in order to parallelize the seq2seq model while avoiding the exposure of bias issues, the input y at the decoding end is... tru ={y true,1 ,y true,2 ,…y true,n Add noise, that is, change the input at the decoding end to y. noise ={y noise,1 ,y noise,2,…y noise,n};

[0146] Among them, y noise The t-th word y noise,t The expression is as follows:

[0147]

[0148] In the above formula, y true,t For y ture The t-th word, α5 is the weight of the fifth hyperparameter, C β For y t The candidate word set, y j C β For any j-th candidate word, p θ (y t =y β |x,y <t When x and y <t Given that y exists, t For y j The probability of.

[0149] It is understandable that the seq2seq model has the following advantages:

[0150] Integrated bidirectional generation of couplets: Makes fuller use of training data, increases fluency and richness, and achieves bidirectional generation;

[0151] By referencing a corpus of non-parallel poems, semantic information is supplemented and semantic richness is enhanced;

[0152] Based on LDA and BPE, the theme embedding of couplets is used to achieve controllable theme generation, and the connection and diversity of meaning are enhanced through theme transformation;

[0153] A loss function was developed to address the antithesis rules, thereby enhancing the antithesis of the generated couplets.

[0154] By using generation direction encoding, topic embedding encoding, length encoding, and genre type encoding, the quality of generated couplets can be comprehensively improved.

[0155] The constructed seq2seq model performs well in terms of couplet fluency and parallelism, and can generate the first line from the second line and the second line from the first line.

[0156] Based on the seq2seq model, this invention provides a deep learning-based method for automatic couplet generation, such as... Figure 1 As shown, the method includes:

[0157] S11. Pre-encode the target upper / lower line;

[0158] The precoding method here is the same as that used for couplet precoding, so it will not be described again.

[0159] S12. Input the pre-encoded target upper line / target lower line into the seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower line / upper line corresponding to the target upper line / target lower line;

[0160] S13. Based on the candidate word probability distribution function of each word segment, generate multiple sets of candidate lower / upper lines corresponding to the target upper / lower line using a high-frequency randomized kernel sampling method;

[0161] Specifically, S13 includes:

[0162] For each word segmentation candidate word probability distribution function, sort each candidate word in the candidate word probability distribution function in descending order of probability;

[0163] Starting from the first candidate word in the sorted sequence, calculate the cumulative probability at each candidate word in the sorted sequence;

[0164] Candidate words in the sorted sequence whose cumulative probability does not exceed the first cumulative probability threshold are assigned to area H; candidate words in the sorted sequence whose cumulative probability exceeds the first cumulative probability threshold but does not exceed the second cumulative probability threshold, whose sorting number does not exceed the sorting threshold, or whose own probability does not exceed the probability threshold are assigned to area M; and candidate words in the sorted sequence other than those in areas H and M are assigned to area L.

[0165] Delete all candidate words in region L, distribute the cumulative probabilities of all candidate words in region L proportionally to candidate words in regions H and M, and correct the probability of each candidate word in region H to the ratio of the cumulative probability of all candidate words in region H to the number of candidate words in region H (that is, adjust the probability distribution within region H to be evenly distributed, while keeping region M unchanged), so as to update the candidate word probability distribution function.

[0166] Randomly sample and combine the probability distribution functions of all candidate words after word segmentation update to obtain multiple sets of alternative lower / upper lines corresponding to the target upper / lower line.

[0167] Figure 2 The example is shown in the comparison graph before and after the candidate word probability distribution function update, which illustrates the change in the search space.

[0168] Existing methods typically use low-diversity algorithms such as clustering algorithms and greedy algorithms to generate couplets, failing to specifically improve the quality of the generated couplets. Therefore, the generated couplets tend to be monotonous in terms of word choice and sentence structure, relying heavily on high-frequency word pairs, and the content of the upper and lower lines is often similar, making it difficult to generate inspiring results. This invention, however, uses a high-frequency randomized kernel sampling method to adjust the search space, thereby improving the novelty and diversity of the generated couplets.

[0169] S14. Select the optimal lower / upper line from the multiple sets of candidate lower / upper lines by scoring, and combine the optimal lower / upper line with the target upper / lower line to obtain a parallel couplet.

[0170] Specifically, S14 includes:

[0171] Delete any candidate lower or upper couplets from the multiple sets of candidate lower / upper couplets that do not conform to the preset antithetical couplet rules;

[0172] Substitute the remaining candidate lower / upper lines into the pre-built antithesis judgment model to obtain the scores of the remaining candidate lower / upper lines;

[0173] The candidate lower / upper line that simultaneously satisfies the condition of having the highest score and a score greater than a preset score threshold will be selected as the optimal lower / upper line.

[0174] Given multiple candidate lower couplets for a given upper couplet, the first step is to filter out couplets that do not conform to simple antithesis rules such as repeated characters using antithesis rules. Then, an antithesis judgment model is used to score the remaining candidate lower couplets. If a couplet with a sufficiently high score exists, the highest-scoring couplet is returned; otherwise, a new set of candidate lower couplets is generated. The process of generating the upper couplet from the lower couplet follows the same logic.

[0175] This invention uses a parallelism judgment module to further ensure the parallelism of the generated couplets.

[0176] Specifically, the construction process of the antithesis judgment model includes:

[0177] Using the aforementioned couplet corpus and a preset negative example construction method, a multi-granularity hybrid negative example dataset is constructed.

[0178] Using the couplet corpus as a positive example dataset, a multi-granularity mixed antithesis judgment dataset is generated, which includes the couplet corpus and the multi-granularity mixed negative example dataset.

[0179] A linear classifier layer is added to the BERT model pre-trained on a corpus of classical poetry to obtain the initial model architecture;

[0180] The initial model architecture is fine-tuned using the multi-granularity hybrid antithesis judgment dataset to obtain the antithesis judgment model;

[0181] Among them, constructing a multi-granularity hybrid negative example dataset by using the couplet corpus and a preset negative example construction method includes:

[0182] Same-frequency replacement ---- Randomly specify any one word segment in the second line of each couplet in the couplet corpus, and use a word segment with a similar word frequency ranking in the character set to replace the any one word segment to obtain a negative example sample correspondingly; Word frequency refers to the frequency of a character appearing in the character set.

[0183] For example: Positive example: The upper couplet: The secluded valley is cloud-supported by the temple; The lower couplet: The cold mountain is snow-entangled by the monk.

[0184] Randomly select "monk" in the lower couplet. In the sub-frequency band near "monk" in the character frequency statistical table corresponding to the character set, there are:

[0185] Ze: 8324; Yan: 8321; Xie: 8314; Ge: 8301; Monk: 8296; Li: 8294; Mirror: 8274; Zun: 8253; Que: 8235;

[0186] Randomly select a replacement character within the similar word frequency. Suppose "mirror" is selected, the negative example corresponds to: The upper couplet: The secluded valley is cloud-supported by the temple; The lower couplet: The cold mountain is snow-entangled by the mirror.

[0187] And / or

[0188] Model replacement ---- Randomly specify any one word segment in the second line of each couplet in the couplet corpus, input the upper couplet of each couplet in the couplet corpus into the encoding end of the seq2seq model, and input the word segments before the any one word segment in the second line of each couplet in the couplet corpus into the decoder of the seq2seq model to obtain the candidate word probability distribution corresponding to the any one word segment. Select a candidate word with a low probability and a high word frequency in the character set from the candidate word probability distribution corresponding to the any one word segment to replace the any one word segment to obtain a negative example sample correspondingly;

[0189] For example: Positive example: The upper couplet: The secluded valley is cloud-supported by the temple; The lower couplet: The cold mountain is snow-entangled by the monk.

[0190] Randomly select "snow" in the lower couplet, input "The secluded valley is cloud-supported by the temple" and "The cold mountain" into the seq2seq model to obtain the candidate word probability distribution;

[0191] Select a candidate word with a low probability and a high word frequency in the character set from the candidate word probability distribution. For example, there are: Phoenix, star, dream, me, bone, spring, flute; Suppose "bone" is randomly selected, the negative example corresponds to: The upper couplet: The secluded valley is cloud-supported by the temple; The lower couplet: The cold mountain is bone-entangled by the monk.

[0192] And / or

[0193] Partial randomization: Randomly select several word segments (e.g., 2 to 4) from the second line of each couplet in the corpus and randomly swap their positions to obtain corresponding negative sample samples;

[0194] Here, it is necessary to ensure that the second line is different before and after the positions are swapped.

[0195] For example: Positive example: First line: Clouds support the temple in the secluded valley; Second line: Snow binds the monk on the cold mountain. Randomly select "cold," "snow," and "bind" from the second line; then randomly shuffle "cold," "snow," and "bind" to "bind," "cold," and "snow." Negative example: First line: Clouds support the temple in the secluded valley; Second line: Snow binds the monk on the cold mountain.

[0196] and / or

[0197] Replace the second line – Randomly replace the second line of each couplet in the corpus with another second line of equal length to obtain corresponding negative sample samples.

[0198] For example: Correct example: First line: Clouds support the temple in the secluded valley; Second line: Snow entangles the monk in the cold mountain.

[0199] Searching for matching couplets includes: "Willows on the bank welcome the gentle breeze," "Nourishing things silently," "Striding towards a well-off life," and "New Year after year, new beginnings." Randomly selecting "Nourishing things silently," the negative example corresponds to the first line: "Clouds support the temple in the secluded valley"; the second line: "Nourishing things silently."

[0200] To increase the relevance of the multi-granularity hybrid antithesis judgment dataset, for couplets containing repeated characters, an additional set of negative examples of same-frequency substitute characters or model substitute characters is constructed for the repeated parts.

[0201] In summary, this invention proposes a more complex and larger-scale seq2seq model that directly controls the parallelism of couplet generation at the loss function level. By combining topic prediction, couplet precoding, high-frequency randomized kernel sampling, and parallelism judgment, it enhances the fluency, parallelism, and novelty of generated couplets, improves the quality of generated second lines, and for the first time realizes a couplet generation mode of "generating first lines for second lines".

[0202] Secondly, the deep learning-based automatic couplet generation device provided by the present invention will be described below. The deep learning-based automatic couplet generation device described below and the deep learning-based automatic couplet generation method described above can be referred to in correspondence. Figure 3 This is a schematic diagram of a deep learning-based automatic couplet generation device, as shown below. Figure 3 As shown, the device includes:

[0203] Precoding module 21 is used to precode the target upper part / target lower part;

[0204] The determination module 22 is used to input the pre-encoded target upper line / target lower line into the seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower line / upper line corresponding to the target upper line / target lower line;

[0205] The generation module 23 is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet by using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function of each word segment;

[0206] The optimization module 24 is used to select the optimal lower / upper line from the multiple sets of candidate lower / upper lines by scoring, and to combine the optimal lower / upper line and the target upper / lower line to obtain a parallel couplet;

[0207] The seq2seq model is a bidirectional generation model for couplets, trained using the TeacherForcing mechanism based on couplet corpora and ancient poetry corpora.

[0208] This invention provides a deep learning-based automatic couplet generation device. It pre-constructs a seq2seq model that performs well in terms of fluency, parallelism, and novelty, enabling both "generating an upper couplet from a lower couplet" and "generating a lower couplet from an upper couplet." Then, the seq2seq model is used to generate a candidate word probability distribution function for each word segment in a given target upper couplet / corresponding lower couplet / upper couplet. Based on this candidate word probability distribution function, a high-frequency randomized kernel sampling method is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / corresponding lower couplet. Finally, a scoring-based selection method is used to select the optimal lower couplet / upper couplet, which is then combined with the target upper couplet / corresponding lower couplet to obtain a parallel couplet. This invention can achieve bidirectional couplet generation and improve the quality of couplet generation based on multi-strategy enhancement.

[0209] Based on the above embodiments, as an optional embodiment, the precoding in the precoding module 21 includes, but is not limited to: topic embedding encoding, length encoding, generation direction encoding, and genre type encoding;

[0210] The generation of direction encoding includes: encoding direction labels PRED-LO or PRED-UP;

[0211] The genre type encoding includes: encoding the genre label IS-CPLT or NOT-CPLT;

[0212] The PRED-LO characterizes the generation of a second line given a first line;

[0213] The PRED-UP characterizes the generation of an upper couplet given a lower couplet.

[0214] The IS-CPLT characterization has a requirement for parallelism;

[0215] The NOT-CPLT characterization indicates that there is no need for symmetry.

[0216] Based on the above embodiments, as an optional embodiment, the precoding module 21 includes a topic embedding unit, which includes:

[0217] The topic inference subunit is used to infer the topic of the target upstream / downstream using a pre-built topic model;

[0218] A topic encoding subunit is used to encode the topic for the target uplink / target downlink;

[0219] The process of constructing the topic model includes:

[0220] Each first line of the couplet corpus, each second line of the couplet corpus, and each sentence of the ancient poetry corpus are treated as a single document;

[0221] Perform word segmentation on each document;

[0222] By using word distribution to represent topics and topic distribution to represent documents, a topic model is constructed that applies to all documents.

[0223] Based on the above embodiments, as an optional embodiment, the apparatus further includes: a first construction module for constructing the seq2seq model, the first construction module comprising:

[0224] An augmentation unit is used to treat each pair of upper and lower lines of poetry in the ancient poetry corpus as a special couplet and add it to the couplet corpus to augment the couplet corpus.

[0225] The precoding unit is used to precode the upper and lower lines of each couplet in the augmented couplet corpus, to obtain samples with the precoded upper line as the given couplet and the precoded lower line as the target couplet, as well as samples with the precoded lower line as the original couplet and the precoded upper line as the target couplet.

[0226] The first dataset construction unit is used to generate the first dataset containing all samples;

[0227] The loss function construction unit is used to construct a loss function based on preset antithetical couplet rules.

[0228] The seq2seq model training unit is used to take the given link in each sample of the first dataset as the input to the encoder and the noise variant of the target link in each sample of the first dataset as the input to the decoder, so as to realize the training of the seq2seq model based on the loss function.

[0229] Based on the above embodiments, as an optional embodiment, x = {x1, x2, ... x} n} represents a given connection, where y = {y1, y2, ... y} n} represents the condition based on x = {x1, x2, ... x} n The corresponding single link generated;

[0230] The preset antithetical couplet rules include, but are not limited to:

[0231] exist When y is not an empty set, t Do not take word segmentation in Chinese;

[0232] exist When y is not an empty set, t Pick word segmentation in Chinese;

[0233] exist When y is not an empty set, t Do not take word segmentation in Chinese;

[0234] Where, x t Let x = {x1, x2, ... x} n The t-th word in}, y t Let y = {y1, y2, ... y n The t-th word in}.

[0235] Based on the above embodiments, as an optional embodiment, the loss function The expression is as follows:

[0236]

[0237] In the above formula, C t ={x1,x2,…x t-1}, where θ is the parameter of the seq2seq model, α1 is the weight of the first hyperparameter, α2 is the weight of the second hyperparameter, α3 is the weight of the third hyperparameter, α4 is the weight of the fourth hyperparameter, and y is the weight of the fourth hyperparameter. <t For the sequence {y1,y2,…y} t-1}, p θ (y t |x,y <t ) is when x and y <t Given the premise that each y exists t The probability of occurrence, p θ (y t |x <t ) is when x <t Given the premise that each y exists tThe probability of occurrence;

[0238] Let x = {x1, x2, ... x} n} represents a given connection, with y true ={y true,1 ,y true,2 ,…y true,n} represents the relationship between x = {x1, x2, ... x} n The target group in the same sample, y true ={y true,1 ,y true,2 ,…y true,n The noise variant of} is y noise ={y noise,1 ,y noise,2 ,…y noise,n};

[0239] Among them, y noise The t-th word y noise,t The expression is as follows:

[0240]

[0241] In the above formula, y true,t For y true The t-th word, α5 is the weight of the fifth hyperparameter, C β For y t The candidate word set, y j C β For any j-th candidate word, p θ (y t =y β |x,y <t ) is when x and y <t Given that y exists, t For y j The probability of.

[0242] Based on the above embodiments, as an optional embodiment, the generation module 23 includes:

[0243] The descending sorting unit is used to sort each candidate word in the candidate word probability distribution function in descending order of probability for each word segmentation.

[0244] The cumulative probability calculation unit is used to calculate the cumulative probability of each candidate word in the sorted sequence, starting from the first candidate word in the sorted sequence.

[0245] The partitioning unit is used to classify candidate words in the sorted sequence whose cumulative probability does not exceed the first cumulative probability threshold into the H region, candidate words in the sorted sequence whose cumulative probability exceeds the first cumulative probability threshold but does not exceed the second cumulative probability threshold, whose sorting number does not exceed the sorting threshold, or whose own probability does not exceed the probability threshold into the M region, and candidate words in the sorted sequence other than those contained in the H and M regions into the L region.

[0246] The update unit is used to delete all candidate words in region L, distribute the cumulative probabilities corresponding to all candidate words in region L to candidate words in regions H and M in a proportional manner, and correct the probability of each candidate word in region H to the ratio of the cumulative probability corresponding to all candidate words in region H to the number of candidate words in region H, so as to update the candidate word probability distribution function.

[0247] The random sampling unit is used to randomly sample and combine the probability distribution functions of all candidate words after word segmentation and update, so as to obtain multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet.

[0248] Based on the above embodiments, as an optional embodiment, the optimization module 24 includes:

[0249] The deletion unit is used to delete the candidate lower couplets / upper couplets that do not conform to the preset antithetical couplet rules from the multiple sets of candidate lower couplets / upper couplets;

[0250] The scoring unit is used to substitute the remaining candidate lower / upper lines into the pre-built antithesis judgment model to obtain the scores of the remaining candidate lower / upper lines.

[0251] The optimal selection unit is used to select the candidate lower / upper line that simultaneously satisfies the highest score and a score greater than a preset score threshold as the optimal lower / upper line.

[0252] Based on the above embodiments, as an optional embodiment, the device further includes a second construction module for constructing a parallelism judgment model, the second construction module comprising:

[0253] A multi-granularity hybrid negative example dataset construction unit is used to construct a multi-granularity hybrid negative example dataset using the couplet corpus and a preset negative example construction method.

[0254] A multi-granularity mixed antithesis judgment dataset construction unit is used to take the couplet corpus as a positive example dataset and generate a multi-granularity mixed antithesis judgment dataset containing the couplet corpus and the multi-granularity mixed negative example dataset;

[0255] The initial network generation unit is used to add a linear classifier layer to the BERT model pre-trained on the classical poetry corpus to obtain the initial model architecture;

[0256] The training unit is used to fine-tune the initial model architecture using the multi-granularity hybrid antithesis judgment dataset to obtain the antithesis judgment model;

[0257] The construction of a multi-granularity hybrid negative example dataset using the couplet corpus and a preset negative example construction method includes:

[0258] Randomly select any word in the second line of each couplet in the couplet corpus, and replace the random word with a word whose character frequency ranking in the character set is similar to the random word to obtain corresponding negative sample samples;

[0259] and / or

[0260] Randomly select any word from the second line of each couplet in the couplet corpus. Input the first line of each couplet in the couplet corpus into the encoder of the seq2seq model. Input the word segment before the random word from the second line of each couplet in the couplet corpus into the decoder of the seq2seq model to obtain the probability distribution of candidate words corresponding to the random word. Select candidate words with low probability and high frequency in the character set from the probability distribution of candidate words corresponding to the random word to replace the random word, so as to obtain the corresponding negative sample.

[0261] and / or

[0262] From the couplet corpus, randomly select several word segments from the second line of each couplet and randomly swap their positions to obtain corresponding negative sample samples;

[0263] and / or

[0264] The second line of each couplet in the corpus is randomly replaced with another second line of equal length to obtain negative sample samples.

[0265] Thirdly, Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a deep learning-based automatic couplet generation method. This method includes: pre-encoding the target upper / lower couplet; inputting the pre-encoded target upper / lower couplet into a seq2seq model to obtain the candidate word probability distribution function for each word segment in the lower / upper couplet corresponding to the target upper / lower couplet; generating multiple sets of candidate lower / upper couplets corresponding to the target upper / lower couplet using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function for each word segment; selecting the optimal lower / upper couplet from the multiple sets of candidate lower / upper couplets through a scoring method, and combining the optimal lower / upper couplet with the target upper / lower couplet to obtain a parallel couplet; wherein the seq2seq model is a bidirectional couplet generation model trained using a Teacher Forcing mechanism based on couplet corpora and classical poetry corpora.

[0266] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0267] Fourthly, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the deep learning-based automatic couplet generation method provided by the above methods. The method includes: pre-encoding a target upper couplet / target lower couplet; inputting the pre-encoded target upper couplet / target lower couplet into a seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower couplet / upper couplet corresponding to the target upper couplet / target lower couplet; generating multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet using a high-frequency randomized kernel sampling method according to the candidate word probability distribution function of each word segment; selecting the optimal lower couplet / upper couplet from the multiple sets of candidate lower couplets / upper couplets through a scoring method, and combining the optimal lower couplet / upper couplet with the target upper couplet / target lower couplet to obtain a parallel couplet; wherein, the seq2seq model is a bidirectional couplet generation model trained using a TeacherForcing mechanism on the basis of couplet corpus and ancient poetry corpus.

[0268] Fifthly, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program is implemented to perform the deep learning-based automatic couplet generation method provided by the above methods. The method includes: pre-encoding a target upper couplet / target lower couplet; inputting the pre-encoded target upper couplet / target lower couplet into a seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower couplet / upper couplet corresponding to the target upper couplet / target lower couplet; generating multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function of each word segment; selecting the optimal lower couplet / upper couplet from the multiple sets of candidate lower couplets / upper couplets through a scoring method, and combining the optimal lower couplet / upper couplet with the target upper couplet / target lower couplet to obtain a parallel couplet; wherein, the seq2seq model is a bidirectional couplet generation model trained using a Teacher Forcing mechanism based on couplet corpora and ancient poetry corpora.

[0269] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0270] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0271] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for automatically generating couplets based on deep learning, characterized in that, The method includes: Pre-encode the target upper / lower line; The pre-encoded target upper / lower line is input into the seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower / upper line corresponding to the target upper / lower line; Based on the candidate word probability distribution function of each word segment, a high-frequency randomized kernel sampling method is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet; The optimal lower / upper line is selected from the multiple sets of candidate lower / upper lines by scoring, and the optimal lower / upper line is combined with the target upper / lower line to obtain a parallel couplet. The seq2seq model is a bidirectional generation model for couplets trained using the Teacher Forcing mechanism, based on the corpus of couplets and ancient poems.

2. The method for automatically generating couplets based on deep learning according to claim 1, characterized in that, The precoding includes, but is not limited to: topic embedding encoding, length encoding, generation direction encoding, and genre type encoding; The generation of direction encoding includes: encoding direction labels PRED-LO or PRED-UP; The genre type encoding includes: encoding genre labels IS-CPLT or NOT-CPLT; The PRED-LO characterizes the generation of a second line given a first line; The PRED-UP characterizes the generation of an upper couplet given a lower couplet. The IS-CPLT characterization has a requirement for parallelism; The NOT-CPLT characterization indicates that there is no need for symmetry.

3. The method for automatically generating couplets based on deep learning according to claim 2, characterized in that, The topic embedding encoding of the target upper / lower line includes: Using a pre-built topic model, infer the topic of the target upper / lower line; Encode the topic for the target upper / lower link; The process of constructing the topic model includes: Each first line of the couplet corpus, each second line of the couplet corpus, and each sentence of the ancient poetry corpus are treated as a single document; Perform word segmentation on each document; By using word distribution to represent topics and topic distribution to represent documents, a topic model is constructed that applies to all documents.

4. The method for automatically generating couplets based on deep learning according to claim 3, characterized in that, The construction process of the seq2seq model includes: Each pair of poems in the ancient poetry corpus is treated as a special couplet and added to the couplet corpus to broaden the couplet corpus; The upper and lower lines of each couplet in the augmented couplet corpus are pre-encoded separately to obtain samples with the pre-encoded upper line as the given couplet and the pre-encoded lower line as the target couplet, as well as samples with the pre-encoded lower line as the original couplet and the pre-encoded upper line as the target couplet. Generate a first dataset containing all samples; A loss function is constructed based on preset antithetical couplet rules; The given link in each sample of the first dataset is used as the input to the encoder, and the noise variant of the target link in each sample of the first dataset is used as the input to the decoder, thereby realizing the training of the seq2seq model based on the loss function.

5. The method for automatically generating couplets based on deep learning according to claim 4, characterized in that, by Indicates a given connection, with Indicates according to The corresponding single-part form was generated; The preset antithetical couplet rules include, but are not limited to: exist When it is not an empty set, Do not take word segmentation in Chinese; exist When it is not an empty set, word segmentation in Chinese; exist When it is not an empty set, Do not take word segmentation in Chinese; in, for The Middle Each word, for The Middle Each word.

6. The method for automatically generating couplets based on deep learning according to claim 5, characterized in that, The loss function The expression is as follows: ; In the above formula, , The parameters of the seq2seq model, The first hyperparameter is the weight. The weights are the second hyperparameter. The third hyperparameter is the weight. The fourth hyperparameter is the weight. For sequence , For when and Under the premise of occurrence, each The probability of occurrence For when Under the premise of occurrence, each The probability of occurrence; by Indicates a given connection, with Indicates and The target group in the same sample, the The noise variant is ; in, Word The expression is as follows: ; In the above formula, for The Middle One word, The fifth hyperparameter is the weight. for The candidate word set for Any of the following 10 candidate words For when and Given the premise that it occurs, for The probability of.

7. The method for automatically generating couplets based on deep learning according to any one of claims 1 to 6, characterized in that, The step of generating multiple sets of candidate lower / upper lines corresponding to the target upper / lower line using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function of each segmented word includes: For each word segmentation candidate word probability distribution function, sort each candidate word in the candidate word probability distribution function in descending order of probability; Starting from the first candidate word in the sorted sequence, calculate the cumulative probability at each candidate word in the sorted sequence; Candidate words in the sorted sequence whose cumulative probability does not exceed the first cumulative probability threshold are assigned to area H; candidate words in the sorted sequence whose cumulative probability exceeds the first cumulative probability threshold but does not exceed the second cumulative probability threshold, whose sorting number does not exceed the sorting threshold, or whose own probability does not exceed the probability threshold are assigned to area M; and candidate words in the sorted sequence other than those in areas H and M are assigned to area L. Delete all candidate words in region L, distribute the cumulative probabilities of all candidate words in region L to candidate words in regions H and M proportionally, and correct the probability of each candidate word in region H to the ratio of the cumulative probability of all candidate words in region H to the number of candidate words in region H, so as to update the candidate word probability distribution function. Randomly sample and combine the probability distribution functions of all candidate words after word segmentation update to obtain multiple sets of alternative lower / upper lines corresponding to the target upper / lower line.

8. The method for automatically generating couplets based on deep learning according to any one of claims 4 to 6, characterized in that, The step of selecting the optimal lower / upper line from the multiple sets of candidate lower / upper lines by scoring includes: Delete any candidate lower or upper couplets from the multiple sets of candidate lower / upper couplets that do not conform to the preset antithetical couplet rules; Substitute the remaining candidate lower / upper lines into the pre-built antithesis judgment model to obtain the scores of the remaining candidate lower / upper lines; The candidate lower / upper line that simultaneously satisfies the condition of having the highest score and a score greater than a preset score threshold will be selected as the optimal lower / upper line.

9. The method for automatically generating couplets based on deep learning according to claim 8, characterized in that, The construction process of the antithesis judgment model includes: Using the aforementioned couplet corpus and a preset negative example construction method, a multi-granularity hybrid negative example dataset is constructed. Using the couplet corpus as a positive example dataset, a multi-granularity mixed antithesis judgment dataset is generated, which includes the couplet corpus and the multi-granularity mixed negative example dataset. A linear classifier layer is added to the BERT model pre-trained on a corpus of classical poetry to obtain the initial model architecture; The initial model architecture is fine-tuned using the multi-granularity hybrid antithesis judgment dataset to obtain the antithesis judgment model; The construction of a multi-granularity hybrid negative example dataset using the couplet corpus and a preset negative example construction method includes: Randomly select any word in the second line of each couplet in the couplet corpus, and replace the random word with a word whose character frequency ranking in the character set is similar to the random word to obtain corresponding negative sample samples; and / or Randomly select any word from the second line of each couplet in the couplet corpus. Input the first line of each couplet in the couplet corpus into the encoder of the seq2seq model. Input the word segment before the random word from the second line of each couplet in the couplet corpus into the decoder of the seq2seq model to obtain the probability distribution of candidate words corresponding to the random word. Select candidate words with low probability and high frequency in the character set from the probability distribution of candidate words corresponding to the random word to replace the random word, so as to obtain the corresponding negative sample. and / or From the couplet corpus, randomly select several word segments from the second line of each couplet and randomly swap their positions to obtain corresponding negative sample samples; and / or The second line of each couplet in the corpus is randomly replaced with another second line of equal length to obtain negative sample samples.

10. A deep learning-based automatic couplet generation device, characterized in that, The device includes: The precoding module is used to precode the target upper / lower line; The determination module is used to input the pre-encoded target upper line / target lower line into the seq2seq model to obtain the candidate word probability distribution function of each word segment in the lower line / upper line corresponding to the target upper line / target lower line; The generation module is used to generate multiple sets of candidate lower couplets / upper couplets corresponding to the target upper couplet / target lower couplet by using a high-frequency randomized kernel sampling method based on the candidate word probability distribution function of each word segment; The optimization module is used to select the optimal lower / upper line from the multiple sets of candidate lower / upper lines by scoring, and to combine the optimal lower / upper line and the target upper / lower line to obtain a parallel couplet; The seq2seq model is a bidirectional generation model for couplets, trained using the Teacher Forcing mechanism based on couplet corpora and ancient poetry corpora.

Citation Information

Patent Citations

  • Antithetical couplet information generation method and device

    CN111126061A

  • Automatic abstract generation method based on kernel sampling

    CN115186089A