Method for generating five-character quatrains based on improved attention mechanism network
By constructing a VGG16 image labeling network and an improved attention mechanism network, and combining image and poetry datasets, the problem of corpus chaos in image-to-ancient poetry conversion was solved, achieving accurate, fast, and complete conversion from images to five-character quatrains, and enhancing the correlation and artistic conception of ancient poems and images.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-19
- Publication Date
- 2026-03-20
AI Technical Summary
Existing technologies for converting images into classical Chinese poems suffer from problems such as chaotic corpus and deviation from image content. Furthermore, they lack effective processing and expansion of image imagery, resulting in generated classical Chinese poems that do not conform to the ancient Chinese poetic principle of "being moved by the scene."
By constructing a VGG16 image labeling network and an improved attention mechanism network, combined with image and poetry datasets, convolutional neural networks are used to extract image features, and five-character quatrains are generated through the attention mechanism. A keyword-correspondence dictionary is established to achieve accurate conversion from images to ancient poems.
It achieves accurate, fast, and complete conversion from images to five-character quatrains, enhancing the connection and artistic conception between ancient poems and images, and conforming to the poetic principle of "evoking emotions through scenery".
Smart Images

Figure CN115545014B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of artificial intelligence text generation, and particularly relates to a natural language processing and ancient poetry text generation method. BACKGROUND
[0002] Chinese traditional ancient poetry is one of the shining gems in the long river of Chinese culture, which is a literary genre that expresses the rich emotions of poets through different images in a highly condensed language and reflects the social life scenes of the people at the same time. Ancient poetry generation is the combination of artificial intelligence and literature and art. In recent years, the ancient poetry generation method using text information has basically realized the function of generating high-quality poetry under the condition of given text. The ancient poetry generation using text requires the selection and expansion of key words under the condition of given ancient poetry content text, so as to automatically generate ancient poetry related to the semantics. This method does not conform to the Chinese ancient poetry rule of "touching the scene to evoke emotions", and the order of poetry is usually to observe the state and changes of objective things, to trigger the poet's thoughts and associations, and then to create artistic realm of poetic and picturesque. The related method of poetry from picture is currently less, and the image words extracted from the picture are not processed and expanded, and there is no larger Chinese ancient poetry corpus training, which leads to some chaotic corpus and errors of deviating from the image content in the poetry. SUMMARY
[0003] The technical problem to be solved by the application is to overcome the shortcomings of the prior art, and to provide an improved attention mechanism network-based five-character quatrains generation method with high conversion accuracy, fast conversion speed and complete conversion.
[0004] The technical solution adopted to solve the above technical problem is composed of the following steps:
[0005] (1) Generating image data set and poetry data set
[0006] Select images from the CIFAR-100 image data set, divide them into a training set and a test set according to a ratio of 5:1, divide the 100 classes in the CIFAR-100 image data set into 10 superclasses, and each image has a class label and a superclass label.
[0007] Select 15000 five-character quatrains of Tang and Song poetry from the Chinese classical anthology database as a five-character quatrains poetry database.
[0008] (2) Constructing a VGG16 picture label network
[0009] The VGG16 picture label network is composed of a first module and a second module, a third module, a front fourth module, a rear fourth module, a global average pooling layer and a Softmax classification layer connected in sequence.
[0010] The first module is composed of 2 convolution layers and 1 pooling layer in series with 64 channels; the second module is composed of 2 convolution layers and 1 pooling layer in series with 128 channels; the third module is composed of 3 convolution layers and 1 pooling layer in series with 256 channels; the first fourth module is composed of 3 convolution layers and 1 pooling layer in series with 512 channels; and the second fourth module is composed of 3 convolution layers and 1 pooling layer in series with 512 channels.
[0011] (3) Training of VGG16 picture label network
[0012] The training set is input into the VGG16 picture label network for training, the batch size is 128, the linear rectifier layer is used as the activation function layer, the learning rate is set to 0.1, the cross-entropy loss function H(p, q) is used to train the VGG16 picture label network, and the training is stopped until the loss function converges:
[0013]
[0014] wherein n represents the number of classifications, n is a finite positive integer, p(x i ) represents the correct answer, and q(x i ) represents the predicted value.
[0015] (4) Extraction of image key label
[0016] The test set is input into the trained VGG16 picture label network for testing, the convolution features are extracted, the output layer uses the Softmax classification layer d1, the images in the test set are classified into 10 categories by the Softmax classification layer d1, the category with the highest probability is taken as the output category, and the image key label is obtained.
[0017] (5) Expansion of poetry data set
[0018] 1) Obtain the poetry from the national folk cultural resource database, the database address is http: / / 51cst.snnu.edu.cn / .
[0019] 2) Add the poetry in the national folk cultural resource database to the quatrains poetry database.
[0020] (6) Poetry data preprocessing
[0021] 1) Convert the traditional Chinese characters in the quatrains poetry database into simplified Chinese characters.
[0022] 2) Delete the rare characters in the quatrains poetry database.
[0023] 3) Delete the poetry with non-Chinese characters in the title of the quatrains poetry database.
[0024] (7) Establish a keyword corresponding dictionary
[0025] A corresponding Chinese character dictionary of 100 picture tags corresponding to the super category keywords [l1, l2,..., l10] is established, wherein l1 represents [river, lake, sea, water, fish], l2 represents [spring, flower, autumn, fall], l3 represents [cup, plate], l4 represents [son, Lang], l5 represents [gold, plate], l6 represents [fly, high], l7 represents [mountain, wild, peak], l8 represents [tower, high, pavilion], l9 represents [tree, forest, branch], and l10 represents [car, road, horse]. The keyword corresponding dictionary is established.
[0026] (8) Construct an improved attention mechanism network
[0027] The improved attention mechanism poem generation network is composed of an encoder and a decoder in series, the encoder is composed of a 1-layer long short-term memory layer b1, the decoder is composed of a long short-term memory layer b2 and a long short-term memory layer b3, and a Softmax classification layer d2 in series, and the long short-term memory layer b2 and the long short-term memory layer b3 have the same structure.
[0028] (9) Training of improved attention mechanism network
[0029] The score WS(V i ) of the node V i is determined by the Word2vec model of the TextRank method according to the following formula:
[0030]
[0031] In the formula, W ji represents the weight of the edge between the node V i and the node V j , In(V i ) represents the node set entering the node i, Out(V j ) represents the node set leaving the node j, the initial value of the score WS(V i ) of the node V i is [0.5, 2], d represents a damping factor, d takes a value of [0.8, 1], and the word with the highest score is selected as the key word of the whole sentence.
[0032] The collected five-character quatrains database is used as a corpus to train the word vector model Word2vec, the word vector dimension T is 256, and the iteration number is 50 times, that is, when a key word is input, a vector space w i and a vector space w j of the word are obtained, and the similarity simi(w i , w j), the series word closest to the keyword semantic is determined according to the size of the similarity, and the first 3 keyword sets {C1, C2,..., C j} with the maximum probability are extracted in sequence:
[0033]
[0034] The encoder encodes the keyword set {C1, C2,..., C j} into the hidden layer state set {h1, h2,..., h j} through a long short-term memory network, j is a limited positive integer, C j is the jth encoding vector; the encoder generates an output sequence {y1, y2,..., y j} using the hidden layer state, and determines the output vector y j according to the following formula:
[0035] y j = argmax P (y | y j-1 , s j , c j )
[0036] s j = f (s j-1 , y j-1 , c j )
[0037] In the formula, y j-1 is the input at the last moment, s j-1 is the state at the last moment, s j is the state at the current moment, and c j is the hidden layer state of all input sequences.
[0038] (10) generating a five-character quatrain
[0039] The test set is input into the trained VGG16 picture label network to obtain the keyword, and the keyword is input into the ancient poem generation network to generate a five-character quatrain.
[0040] In the (2) step of the application, the convolution kernel of the convolution layer is 3*3, and the step length is 1; the filter of the pooling layer is 2*2, and the step length is 2; the channel number of the global average pooling layer is 512.
[0041] In the (6) step of the application, the method for converting traditional Chinese characters into simplified Chinese characters is: using a simplified and traditional Chinese conversion word library to perform simplified and traditional Chinese conversion operation on all poems; the method for deleting poems with non-Chinese characters in the title of the five-character quatrain poem database is: using a regular expression method to delete poems with blanks, periods, special symbols and non-standard titles in the title.
[0042] The long short-term memory layer b1 outputs a spatial dimension of 4, and the long short-term memory layer b2 and the long short-term memory layer b3 output a spatial dimension of 20.
[0043] The present application has the following advantages compared with the prior art:
[0044] The entity label after feature extraction and classification of the user input picture is enhanced in association with the picture, and the generality and integrity of the whole ancient poem atmosphere are increased. The output result is obtained by expanding the ancient poem training data set and the keyword. The fusion between different technical fields of the image feature extraction model established by the VGG16 network and the encoding-decoding poetry model improved based on the attention mechanism is explored, and the method of converting a graph into a five-character quatrains is explored, and the purpose of looking at a picture and making a poem is realized. The present application has the advantages of accurate conversion, fast conversion speed, complete conversion and the like, and can be used to convert an image into a five-character quatrains. BRIEF DESCRIPTION OF DRAWINGS
[0045] Figure 1 is a flowchart of embodiment 1 of the present application.
[0046] Figure 2 is a structural schematic diagram of the VGG16 picture label network.
[0047] Figure 3 is a structural schematic diagram of the improved attention mechanism network.
[0048] Figure 4 is an effect diagram of converting a graph in the test set into a five-character quatrains. DETAILED DESCRIPTION
[0049] The present application will be further described in detail below in combination with the drawings and embodiments, but the present application is not limited to the following embodiments.
[0050] Embodiment 1
[0051] In Figure 1 , the five-character quatrains generation method based on the improved attention mechanism network of the present embodiment comprises the following steps:
[0052] (1) Generating image data set and poem data set
[0053] Select images from the CIFAR-100 image data set, divide them into a training set and a test set according to a ratio of 5:1, divide the 100 classes in the CIFAR-100 image data set into 10 superclasses, and each image has a class label and a superclass label.
[0054] Select 15,000 five-character quatrains of Tang and Song poems from the Chinese classical literature database as a five-character quatrains database.
[0055] (2) Constructing a VGG16 image tagging network
[0056] The VGG16 image labeling network consists of a first module, a second module, a third module, a pre-fourth module, a post-fourth module, a global average pooling layer, and a Softmax classification layer d1, which are connected in series.
[0057] exist Figure 2 In this embodiment, the first module consists of two convolutional layers with 64 channels connected in series and one pooling layer connected in series; the second module consists of two convolutional layers with 128 channels connected in series and one pooling layer connected in series; the third module consists of three convolutional layers with 256 channels connected in series and one pooling layer connected in series; the first fourth module consists of three convolutional layers with 512 channels connected in series and one pooling layer connected in series; and the last fourth module consists of three convolutional layers with 512 channels connected in series and one pooling layer connected in series. In this embodiment, the convolutional kernels of the convolutional layers are 3×3 with a stride of 1; the filters of the pooling layers are 2×2 with a stride of 2; and the global average number of pooling layer channels is 512.
[0058] (3) Training the VGG16 image labeling network
[0059] The training set was fed into the VGG16 image labeling network for training, with a batch size of 128. Linear rectified layers were used as activation layers, and the learning rate was set to 0.1. The VGG16 image labeling network was trained using the cross-entropy loss function H(p,q) until the loss function converged.
[0060]
[0061] Where n represents the number of categories, and n is a finite positive integer, p(x i ) represents the correct answer, q(x) i () indicates the predicted value.
[0062] (4) Extract key tags from images
[0063] The test set is input into the trained VGG16 image labeling network for testing. Convolutional features are extracted, and the output layer uses a Softmax classification layer d1. The Softmax classification layer d1 divides the images in the test set into 10 categories based on their probabilities. The category with the highest probability is taken as the output category, thus obtaining the key labels of the images.
[0064] (5) Expanding the poetry dataset
[0065] 1) Obtain poems from the National Folk Culture Resources Database, the database address is http: / / 51cst.snnu.edu.cn / ;
[0066] 2) Add poems from the ethnic and folk cultural resources database to the five-character quatrain poetry database.
[0067] (6) Poetry data preprocessing
[0068] 1) Convert the traditional Chinese characters in the five-character quatrains poetry database to simplified Chinese characters. The method for converting traditional Chinese characters to simplified Chinese characters is to use a simplified and traditional Chinese conversion word library to perform simplified and traditional Chinese conversion on all poems.
[0069] 2) Delete rare characters in the five-character quatrains poetry database.
[0070] 3) Delete poems with non-Chinese characters in the title of the five-character quatrains poetry database. The method for deleting poems with non-Chinese characters in the title of the five-character quatrains poetry database is to use a regular expression method to delete poems with blanks, periods, special symbols, and non-standard titles in the title.
[0071] (7) Establish a keyword corresponding dictionary
[0072] A corresponding Chinese character dictionary of 100 picture tags corresponding to super-category keywords [l1, l2,..., l10] is established, where l1 represents [river, lake, sea, water, fish], l2 represents [spring, flower, autumn, fall], l3 represents [cup, plate], l4 represents [son, young man], l5 represents [gold, plate], l6 represents [fly, high], l7 represents [mountain, wild, peak], l8 represents [tower, high, pavilion], l9 represents [tree, forest, branch], and l10 represents [car, road, horse]. A keyword corresponding dictionary is established.
[0073] (8) Construct an improved attention mechanism network
[0074] In the Figure 3 , the improved attention mechanism poetry generation network of the present embodiment is composed of an encoder and a decoder in series, the encoder is composed of a 1-layer long short-term memory layer b1, the decoder is composed of a long short-term memory layer b2 and a long short-term memory layer b3, and a Softmax classification layer d2 in series, and the long short-term memory layer b2 and the long short-term memory layer b3 have the same structure. The output space dimension of the long short-term memory layer b1 of the present embodiment is 4, and the output space dimension of the long short-term memory layer b2 and the long short-term memory layer b3 is 20.
[0075] (9) Training the improved attention mechanism network
[0076] The score WS(V i ) of the node V i is determined by the Word2vec model of the TextRank method according to the following formula:
[0077]
[0078] In the formula, W ji represents the node V iand node V j weight of edge, In(V i ) represents node set entering node i, Out(V j ) represents node set leaving node j, score WS(V i ) of node V i , initial value of WS(V i ) is [0.5, 2], initial value of WS(V i ) in the embodiment is 1, d represents damping factor, d takes value [0.8, 1], d takes value 0.85 in the embodiment, and the word with the highest score is selected as the keyword of the whole sentence.
[0079] The collected five-character quatrains database is used as a corpus to train the word vector model Word2vec, the word vector dimension T is 256, and the iteration number is 50 times, that is, when a keyword is input, a vector space w i and a vector space w j are obtained, the similarity simi(w i , w j ) between the vectors is determined according to the following formula, the series of words closest to the semantic of the keyword are determined according to the size of the similarity, and the first three keyword sets {C1, C2,..., C j} with the maximum probability are extracted in order:
[0080]
[0081] The encoder encodes the keyword set {C1, C2,..., C j} into the hidden layer state set {h1, h2,..., h j} through the long short-term memory network, j is a limited positive integer, and C j is the jth encoding vector; the encoder generates the output sequence {y1, y2,..., y j} by using the hidden layer state, and the output vector y j is determined according to the following formula:
[0082] y j =argmaxP(y|y j-1 ,s j ,c j )
[0083] s j =f(s j-1 ,y j-1 ,c j )
[0084] In the formula, y j-1 is the input at the last moment, s j-1 is the state at the last moment, s j is the state at the current moment, and cj is the hidden layer state of all input sequences.
[0085] (10) generating a five-character quatrain
[0086] The test set is input into the trained VGG16 picture label network to obtain the keyword, and the keyword is input into the ancient poem generation network to generate a five-character quatrain.
[0087] The improved attention mechanism network-based five-character quatrain generation method is completed.
[0088] Embodiment 2
[0089] The improved attention mechanism network-based five-character quatrain generation method of this embodiment consists of the following steps:
[0090] (1) generating an image data set and a poem data set
[0091] This step is the same as in embodiment 1.
[0092] (2) constructing a VGG16 picture label network
[0093] This step is the same as in embodiment 1.
[0094] (3) training the VGG16 picture label network
[0095] This step is the same as in embodiment 1.
[0096] (4) extracting image key labels
[0097] This step is the same as in embodiment 1.
[0098] (5) expanding the poem data set
[0099] This step is the same as in embodiment 1.
[0100] (6) poem data preprocessing
[0101] This step is the same as in embodiment 1.
[0102] (7) establishing a keyword corresponding dictionary
[0103] This step is the same as in embodiment 1.
[0104] (8) constructing an improved attention mechanism network
[0105] This step is the same as in embodiment 1.
[0106] (9) training the improved attention mechanism network
[0107] The Word2vec model using the TextRank method determines the node V according to the following formula iscore WS(V i ) of the node V
[0108]
[0109] wherein W ji denotes the weight of the edge between the node V i and the node V j , In(V i ) denotes the node set entering the node i, Out(V j ) denotes the node set leaving the node j, the initial value of the score WS(V i ) of the node V i is [0.5, 2], the initial value of the score WS(V i ) of the node V i in this embodiment is 0.5, and d denotes a damping factor, d takes a value of [0.8, 1], and d takes a value of 0.80 in this embodiment. The word with the highest score is selected as the key word of the whole sentence.
[0110] The other steps of this step are the same as those in Embodiment 1.
[0111] The other steps are the same as those in Embodiment 1. The improved attention mechanism network-based quatrains generation method is completed.
[0112] Embodiment 3
[0113] The improved attention mechanism network-based quatrains generation method in this embodiment comprises the following steps:
[0114] (1) Generating an image data set and a poem data set
[0115] This step is the same as that in Embodiment 1.
[0116] (2) Constructing a VGG16 picture label network
[0117] This step is the same as that in Embodiment 1.
[0118] (3) Training the VGG16 picture label network
[0119] This step is the same as that in Embodiment 1.
[0120] (4) Extracting image key labels
[0121] This step is the same as that in Embodiment 1.
[0122] (5) Expanding the poem data set
[0123] This step is the same as that in Embodiment 1.
[0124] (6) Poem data preprocessing
[0125] This step is the same as that in Embodiment 1.
[0126] (7) Establish a keyword corresponding dictionary
[0127] This step is the same as example 1.
[0128] (8) Construct an improved attention mechanism network
[0129] This step is the same as example 1.
[0130] (9) Train the improved attention mechanism network
[0131] The score WS(V i ) of the node V i of the Word2vec model adopting the TextRank method is determined by the following formula:
[0132]
[0133] In the formula, W ji represents the weight of the edge between the node V i and the node V j , In(V i ) represents the node set entering the node i, Out(V j ) represents the node set leaving the node j, the initial value of the score WS(V i ) of the node V i is [0.5, 2], the initial value of the score WS(V i ) of the node V i in this embodiment is 2, d represents a damping factor, d takes a value of [0.8, 1], d takes a value of 1.0 in this embodiment, and the word with the highest score is selected as the keyword of the whole sentence.
[0134] The other steps of this step are the same as example 1.
[0135] The other steps are the same as example 1. The improved attention mechanism network-based five-character quatrains generation method is completed.
[0136] In order to verify the beneficial effects of the present application, the inventors carried out a simulation experiment by using the improved attention mechanism network-based five-character quatrains generation method of example 1 of the present application, and the experimental conditions are as follows:
[0137] 1. Simulation conditions
[0138] Software environment: PyCharm 2019.3.1x64.
[0139] The hardware condition is 1 Lenovo computer.
[0140] Computer configuration:
[0141] 1) Processor: IntelI CoreI i7-10700 CPU@2.90GHz 2.90GHz.
[0142] 2) Memory: 32.0GB.
[0143] The software platform is: tensorflow1.12.0 framework.
[0144] Other third-party libraries: numpy1.19.5, gensim 3.3.0, matplotlib, scipy1.2.1.
[0145] Input the test set pictures in the CIFAR-100 image dataset, as Figure 4 shown, input into the VGG16 image label network to extract the entity label "castle", corresponding to the keyword dictionary l8, and obtain the keyword "building". Through the expansion of keywords, we get "building", "pavilion", "platform", and "tower". Input into the ancient poem generation network, the output results are 4 five-character quatrains. The first one is: "What's the matter with being drunk? Recognize the beautiful surroundings in the high and secluded place. In the morning, there is a magnificent high view, and the high building hangs over the shore." The second one is: "The auspicious view is like a fairy's nest on high, and the plum tree hides the greenery. The great dragon faces the north veranda, and the colorful years are paved with jade altars." The third one is: "How new the high pavilion is! On the last day, view the building gate. The green hall is surrounded by the evening pavilion, and the spring in the palace collects at the horse gate." The fourth one is: "The auspicious omen accommodates thousands of rooms, and the time of the dancing pavilion in Pengcheng. The new sun comes here to wash away the dust, and the palace platform faces the east pond."
[0146] The present invention has the following advantages compared with the prior art:
[0147] The keywords with similar semantics expanded from the labels extracted from the image in the present invention ensure a high degree of association between the five-character quatrains and the pictures; the long short-term memory network model with an attention mechanism is used to complete the generation of five-character quatrains, ensuring the coherence and continuity of the generated content; through the integration of different technical fields of the image feature extraction model established by the VGG16 network and the encoding-decoding poem-making model improved based on the attention mechanism, the conversion of images into five-character quatrains is achieved. The present invention has the advantages of accurate conversion, fast conversion speed, and complete conversion, and can be used to convert images into five-character quatrains.
Claims
1. A method for generating five-character quatrains based on an improved attention mechanism network, characterized in that... It consists of the following steps: (1) Generate image datasets and poetry datasets Images were selected from the CIFAR-100 image dataset and divided into training and test sets in a 5:1 ratio. The 100 classes in the CIFAR-100 image dataset were divided into 10 superclasses, and each image was assigned a class label and a superclass label. 15,000 five-character quatrains from Tang and Song dynasty poems were selected from the Chinese Classical Literature Collection Database to form a database of five-character quatrain poems. (2) Constructing a VGG16 image tagging network The VGG16 image labeling network consists of the first module, the second module, the third module, the pre-fourth module, the post-fourth module, the global average pooling layer, and the Softmax classification layer d1, which are connected in series. The first module consists of two convolutional layers with 64 channels connected in series and one pooling layer connected in series; the second module consists of two convolutional layers with 128 channels connected in series and one pooling layer connected in series; the third module consists of three convolutional layers with 256 channels connected in series and one pooling layer connected in series; the first fourth module consists of three convolutional layers with 512 channels connected in series and one pooling layer connected in series; the last fourth module consists of three convolutional layers with 512 channels connected in series and one pooling layer connected in series. (3) Training the VGG16 image labeling network The training set was fed into the VGG16 image labeling network for training, with a batch size of 128. Linear rectified layers were used as activation layers, and the learning rate was set to 0.
1. The VGG16 image labeling network was trained using the cross-entropy loss function H(p,q) until the loss function converged. Where n represents the number of categories, and n is a finite positive integer, p(x i ) represents the correct answer, q(x) i () represents the predicted value; (4) Extract key tags from images The test set is input into the trained VGG16 image labeling network for testing. Convolutional features are extracted, and the output layer uses a Softmax classification layer d1. The Softmax classification layer d1 divides the images in the test set into 10 categories based on their probability. The category with the highest probability is taken as the output category, and the key labels of the images are obtained. (5) Expanding the poetry dataset 1) Obtain poems from the National Folk Culture Resources Database, the database address is http: / / 51cst.snnu.edu.cn / ; 2) Add poems from the ethnic folk culture resource database to the five-character quatrain poetry database; (6) Preprocessing of poetry data 1) Convert traditional Chinese characters in the database of five-character quatrain poems to simplified Chinese characters; 2) Remove uncommon characters from the database of five-character quatrain poems; 3) Delete poems whose titles in the database of five-character quatrains contain non-Chinese characters; (7) Establish a keyword-correspondence dictionary A dictionary of corresponding Chinese characters for 100 super-category keywords [l1,l2,...,l10] corresponding to image tags was created, where l1 represents [river, lake, sea, water, fish], l2 represents [spring, flower, autumn, fall], l3 represents [cup, plate], l4 represents [son, young man], l5 represents [gold, plate], l6 represents [fly, high], l7 represents [mountain, wild, peak], l8 represents [building, high, pavilion], l9 represents [tree, forest, branch], and l10 represents [car, road, horse]. A keyword correspondence dictionary was thus established. (8) Construct an improved attention mechanism network The ancient poetry generation network with improved attention mechanism consists of an encoder and a decoder connected in series. The encoder consists of a long short-term memory layer b1, and the decoder consists of long short-term memory layer b2, long short-term memory layer b3, and Softmax classification layer d2 connected in series. The long short-term memory layer b2 and long short-term memory layer b3 have the same structure. (9) Training an improved attention mechanism network The Word2vec model using the TextRank method determines node V according to the following formula. i The score WS(V) i ): In the formula, W ji Represents node V i and node V j The weight of the edge, In(V) i ) represents the set of nodes that enter node i, and Out(V j V represents the set of nodes that leave node j. i The score WS(V) i The initial value of ) is [0.5,2], d represents the damping factor, and d takes the value [0.8,1]. The word with the highest score is selected as the keyword of the whole sentence. The Word2vec word vector model was trained using a database of collected five-character quatrains as the corpus. The word vector dimension T was set to 256, and the number of iterations was 50. That is, when one keyword is input, one vector space w of the word is obtained. i and vector space w j The similarity between vectors, simi(w), is determined by the following formula. i ,w j The similarity score determines the series of words that are semantically closest to the keyword, and the top 3 keywords with the highest probability are extracted in order {C1, C2, ..., C}. j }: The encoder will use the keyword set {C1, C2, ..., C} j The hidden state set {h1, h2, ..., h} is encoded through a Long Short-Term Memory network. j }, where j is a finite positive integer, C j Let be the j-th encoded vector; the encoder generates the output sequence {y1, y2, ..., yj} using the hidden state. j The output vector y is determined by the following formula. j : y j =argmaxP(y|y j-1 ,s j ,c j ) s j =f(s j-1 ,y j-1 ,c j ) In the formula, y j-1 s is the input from the previous time step. j-1 s represents the state at the previous moment. j c represents the current state. j These are the hidden states of all input sequences; (10) Generate five-character quatrains The test set is input into the trained VGG16 image labeling network to obtain keywords. The keywords are then input into the ancient poetry generation network to generate five-character quatrains.
2. The method for generating five-character quatrains based on an improved attention mechanism network according to claim 1, characterized in that: In step (2), the convolution kernel of the convolutional layer is 3×3 with a stride of 1; the filter of the pooling layer is 2×2 with a stride of 2; and the number of channels in the global average pooling layer is 512.
3. The method for generating five-character quatrains based on an improved attention mechanism network according to claim 1, characterized in that... In step (6), the method for converting traditional Chinese characters to simplified Chinese characters is to use a simplified-traditional conversion dictionary to perform simplified-traditional conversion on all the poems; the method for deleting poems that do not contain Chinese characters from the title of the five-character quatrain poetry database is to use regular expressions to delete poems that contain blanks, periods, special symbols, or non-standard titles.
4. The method for generating five-character quatrains based on an improved attention mechanism network according to claim 1, characterized in that: In step (8), the output space dimension of the long short-term memory layer b1 is 4, and the output space dimension of the long short-term memory layers b2 and b3 is 20.
Citation Information
Patent Citations
Ancient poetry generation method of based on image content
CN107480132A
Method for converting pictures into Chinese ancient poems based on neural network model
CN107832292A