Tut characteristic extractor training method, poem generation method, device and storage medium
By constructing a training model and using a graph feature extractor to extract imagery word features from the knowledge graph of poetry creation, the problem of existing models being unable to flexibly use imagery words is solved, and poems with artistic conception are generated.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG INST OF ARTIFICIAL INTELLIGENCE & ADVANCED COMPUTING
- Filing Date
- 2022-10-25
- Publication Date
- 2026-05-08
AI Technical Summary
Existing Chinese poetry generation models cannot flexibly use imagery words, resulting in generated poems that lack artistic conception.
By constructing a training model, including a graph feature extractor, a topic feature extractor, and a poem feature extractor, relevant imagery word features are extracted from topic words using a knowledge graph of poetry creation. The parameters of the graph feature extractor are adjusted so that it can flexibly use imagery words when generating poems.
It enables the flexible use of imagery words when generating poems, producing poems with artistic conception and improving the quality of poetry creation.
Smart Images

Figure CN115599887B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to a graph feature extractor training method, a poetry generation method, an apparatus, and a storage medium. Background Technology
[0002] Classical poetry is a gem of traditional culture and a condensation of the spiritual culture of the Chinese nation. Current Chinese poetry generation technology has achieved good results. Poems generated by various poetry generation models are not only diverse in style and form, but also have perfect parallelism and rhyme.
[0003] However, existing poetry generation models all suffer from the problem of not being able to flexibly use imagery words when generating poems. Whether expressing emotions through scenery or recording events realistically, imagery words play a very important role in poetry. At the same time, imagery words are also the foundation for forming artistic conception. The inability to flexibly use imagery words makes automatically generated poems lack artistic conception. Summary of the Invention
[0004] This invention provides a graph feature extractor training method, a poetry generation method, a device, and a storage medium to solve the problem that existing Chinese poetry generation models cannot flexibly use imagery words when generating poems, resulting in automatically generated poems lacking artistic conception.
[0005] In a first aspect, the present invention provides a graph feature extractor training method, comprising:
[0006] Acquire training data, which includes keywords and sample poems;
[0007] Based on the stated theme, search for sub-graphs matching the stated theme from the knowledge graph of poetry creation, wherein the knowledge graph of poetry creation includes imagery words;
[0008] A training model is constructed, which includes a graph feature extractor to be trained, a pre-trained topic feature extractor, and a pre-trained poem feature extractor. The output layers of the graph feature extractor, the topic feature extractor, and the poem feature extractor are connected to the output layer of the training model. The training model is used to train the graph feature extractor to extract features related to the topic words and the poem samples from the sub-graph.
[0009] The sub-graph is input into the graph feature extractor, the topic words are input into the topic feature extractor, and the poem samples are input into the poem extractor, so as to output feature vectors in the output layer of the training model;
[0010] The parameters of the graph feature extractor are adjusted based on the feature vector.
[0011] Secondly, the present invention provides a method for generating poetry, including:
[0012] Obtain the input data required for poetry generation, including keywords;
[0013] Based on the stated theme, search for sub-graphs matching the stated theme from the knowledge graph of poetry creation, wherein the knowledge graph of poetry creation includes imagery words;
[0014] The input data and the sub-graph are input into a pre-trained poetry generation model to generate poems, and the sub-graph is input into the graph feature extractor of the poetry generation model.
[0015] The graph feature extractor is trained using the graph feature extractor training method described in the first aspect.
[0016] Thirdly, the present invention provides an electronic device, the electronic device comprising:
[0017] At least one processor; and
[0018] A memory communicatively connected to the at least one processor; wherein,
[0019] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the graph feature extractor training method of the first aspect of the present invention, and / or the poetry generation method of the second aspect.
[0020] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions that cause a processor to execute and implement the graph feature extractor training method of the first aspect of the present invention, and / or the poetry generation method of the second aspect.
[0021] The graph feature extractor training method of this invention first acquires training data, which includes topic words and poem samples. Based on the topic words, it searches for sub-graphs matching the topic words in the poetry creation knowledge graph. Since the poetry creation knowledge graph includes imagery words, the sub-graphs also include imagery words. A training model is constructed, comprising a graph feature extractor to be trained, a pre-trained topic feature extractor, and a pre-trained poem sample feature extractor. The output layers of the graph feature extractor, topic feature extractor, and poem sample feature extractor are connected to the output layer of the training model. The training model is used to train the graph feature extractor to extract features related to topic words and poem samples from the sub-graphs. The sub-graphs are input into the graph feature extractor, the topic words are input into the topic feature extractor, and the poem samples are input into the poem sample feature extractor to output feature vectors at the output layer of the training model. The parameters of the graph feature extractor are adjusted based on the feature vectors. By employing a topic feature extractor and a poem feature extractor in conjunction with a trained graph feature extractor, the graph feature extractor can extract graph features related to topic words and poem samples from sub-graphs. Since the sub-graphs also include image words, the graph features also include image word features related to topic words and poem samples. In other words, the trained graph feature extractor can flexibly extract image word features from the sub-graphs. When generating poems, the sub-graphs are input into a pre-trained poem generation model, which can generate poems with artistic conception based on the image word features in the sub-graphs. This achieves the flexible use of image words to generate poems with artistic conception.
[0022] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a flowchart of a graph feature extractor training method provided in Embodiment 1 of the present invention;
[0025] Figure 2 This is a schematic diagram of a knowledge graph structure for poetry creation provided in Embodiment 1 of the present invention;
[0026] Figure 3 This is a schematic diagram of a sub-map search process provided in Embodiment 1 of the present invention;
[0027] Figure 4 This is a schematic diagram of the sub-map structure provided in Embodiment 1 of the present invention;
[0028] Figure 5 This is a schematic diagram of the structure of the training model provided in Embodiment 1 of the present invention;
[0029] Figure 6 This is a flowchart of a poetry generation method provided in Embodiment 2 of the present invention;
[0030] Figure 7 This is a schematic diagram of the structure of the electronic device provided in Embodiment 3 of the present invention. Detailed Implementation
[0031] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0032] Example 1
[0033] Figure 1 This is a flowchart of a graph feature extractor training method provided in Embodiment 1 of the present invention. This embodiment is applicable to the training of a graph feature extractor, which is used to extract graph features from a knowledge graph. This method can be executed by a computer used to train the model, and the computer can be configured in an electronic device. Figure 1 As shown, the training method for this graph feature extractor includes:
[0034] S101. Obtain training data, which includes keywords and poem samples.
[0035] A theme guides the creation of poetry. Poems are typically generated based on a specific theme, such as longing for one's hometown, pastoral landscapes, farewells, or historical reflections. The theme words are those corresponding to the theme. Sample verses are poems that are related to the theme words and possess evocative imagery.
[0036] A training database can be pre-set, with multiple topic words of different themes. For each topic word, multiple sets of associated poems can be set. Then, topic words can be randomly obtained, and when a topic word is determined, a sample of poems associated with that topic word can be randomly obtained. The obtained topic words and sample poems can be used as training data.
[0037] S102. Search for a sub-graph that matches the subject term from the knowledge graph of poetry creation. The knowledge graph of poetry creation includes image words.
[0038] An image is an objective image used to express subjective feelings when creating poetry, and it is also the main body that makes the poetry have artistic conception. An image word is the name of the image. For example, the bright moon can be used to express homesickness, so "bright moon" can be used as an image word. For a computer, the usage of image words can be understood as a rule and can be deduced.
[0039] The knowledge graph of poetry creation includes multiple nodes and the attributes between adjacent nodes. Each node corresponds to a word, and the attributes between adjacent nodes are the attributes between the words corresponding to adjacent nodes. For example Figure 2 As shown in a poetry creation word spectrum shown in this embodiment, among them, the attribute between "lovesickness" and "missing" is "belong to", which means that "lovesickness" belongs to "missing", and the attribute between "wild geese" and "lovesickness" is "implies", which means that "wild geese" implies "lovesickness". For poetry creation, the words corresponding to each node include the subject term and the image words corresponding to the subject term. The image words included in the knowledge graph of poetry creation are the image words related to the subject term.
[0040] Searching for a sub-graph that matches the subject term from the knowledge graph of poetry creation means extracting a sub-graph from the knowledge graph of poetry creation that contains image words related to the subject term. The node with the most similar semantics to the subject term can be found from the knowledge graph of poetry creation as the root node, and then the nodes adjacent to the root node are searched. A sub-graph is formed according to the root node, the nodes adjacent to the root node, and the attributes between the nodes.
[0041] In an optional embodiment of the present invention, as Figure 3 shown is a schematic flowchart of searching for a sub-graph that matches the subject term from the knowledge graph of poetry creation. Searching for a sub-graph that matches the subject term from the knowledge graph of poetry creation includes:
[0042] S1011. Search for the node with the most similar semantics to the subject term from the knowledge graph of poetry creation as the root node.
[0043] Keywords can be manually provided or randomly selected from a training database. However, for the same topic, there may be multiple ways to express it. For example, for the topic "homesickness," the keywords could be "longing for one's hometown" or "missing one's hometown." Therefore, since the given keywords may not be included in the poetry creation knowledge graph, the root node can be selected from the knowledge graph based on the semantic similarity to the keywords. Specifically, the semantics of the known keywords and the semantics of each node in the poetry creation knowledge graph can be obtained separately. Then, the semantic similarity between the keywords and the semantics of each node can be calculated, and the node with the highest semantic similarity can be selected as the root node. For example, if the known keyword is "longing for one's hometown," and the semantics of "homesickness" in the poetry creation knowledge graph are most similar to "missing one's hometown," then the node containing "homesickness" can be selected as the root node. It should be noted that the root node is generally a keyword in the poetry creation knowledge graph, not an image word representing an object.
[0044] S1012. Calculate the path length from each node to the root node in the knowledge graph based on the attributes of two adjacent nodes in the poetry creation knowledge graph.
[0045] Path length can be used to determine the degree of association between a node and the root node; the longer the path length, the lower the degree of association between the node and the root node. Two nodes inherently have the same path length, but given the inclusion of keywords, the degree of association between each node and the keywords must also be considered. For example, among multiple nodes adjacent to the root node, if two adjacent nodes have different attributes, the degree of association between each adjacent node and the keywords will also differ. The same applies to other nodes. To distinguish nodes with different attributes, different path lengths can be pre-set for adjacent nodes with different attributes. For instance, if the attribute of two adjacent nodes is "parallelism," the path length between them is 2; if the attribute is "belongs to," the path length between them is 3. Then, the path lengths between all nodes from a given node to the root node are added together to obtain the path length from each node to the root node.
[0046] In one example of this embodiment, for each node in the poetry creation knowledge graph, the shortest path between the node and the root node can be determined; the number of paths with preset attributes in the shortest path can be counted, and the product of the number of paths and the penalty factor can be calculated; the length of the shortest path and the sum of the product can be calculated as the path length from the node to the root node.
[0047] There may be one or more paths from different nodes to the root node. When multiple paths exist, their lengths may differ. Therefore, the shortest path between two nodes can be used to calculate the path length. The preset attribute indicates a low correlation between a node and the topic word. In this embodiment, when the path from the current node to the root node includes a path with the preset attribute, a penalty mechanism can be used to calculate the path length between the two nodes. Regarding the penalty mechanism, it can be understood that when a user wants to create a poem with the topic "homesickness," "homesickness" belongs to a subcategory of "longing," but when creating poetry with the theme "homesickness," it generally doesn't rise to the broader category of "longing." Therefore, the path length from "homesickness" to "longing" can be calculated using a penalty mechanism. Similarly, "longing" and "homesickness" both belong to the subcategory of "longing," but they are related by origin but not meaning. "Longing" has deviated from the semantics of "homesickness," and their correlation is low; therefore, a penalty mechanism can also be used to calculate their length.
[0048] For example, the formula for calculating path length is: D = d + d_penalty * n, where D is the path length between two nodes, d is the path length of the shortest path between the two nodes, d_penalty is the penalty factor, and n is the number of paths in the shortest path whose attribute is a preset attribute. For example, the preset attribute is set to "belongs to", and the penalty factor is 3, such as... Figure 2 As shown, the shortest path length between "red bean" and "longing" is 3, and the number of paths with the attribute "belongs to" is 2. Therefore, the path length from "red bean" to "longing" is 3 + 3 * 2 = 9.
[0049] By setting a penalty factor to calculate the path length, the path lengths between nodes with different attributes differ significantly. This allows for the differentiation of nodes whose paths to the root node contain paths with preset attributes. For example, when a node's path to the root node contains a path with a preset attribute, the penalty factor results in a longer path length from that node to the root node, indicating a lower relevance of that node to the keyword. Consequently, that node is more likely to be filtered out.
[0050] S1013. Nodes with path lengths less than a preset length threshold are identified as target nodes, and a sub-graph matching the keyword is obtained.
[0051] Nodes with different attributes have different path lengths. Setting a length threshold can restrict the semantics of nodes in a subgraph, that is, restrict the semantics of image words. On the other hand, setting a length threshold can limit the number of nodes in a subgraph. The smaller the length threshold, the shorter the allowed path length between nodes, and the fewer nodes and image words the subgraph includes; the larger the length threshold, the more nodes and image words the subgraph includes. Figure 4 The diagram shown is a subgraph obtained with "homesickness" as the root node.
[0052] In this example, a penalty mechanism is set up to calculate the path length of paths with preset attributes when calculating the path length. This can distinguish nodes whose paths to the root node contain paths with preset attributes. Then, a length threshold is set to limit the number of nodes in the subgraph. The path lengths between nodes with different attributes are different, which is equivalent to restricting the semantics of the image words corresponding to the nodes in the subgraph. This is to filter out nodes whose relationship with the root node is a preset attribute. In other words, nodes that are unrelated to the topic or have a low degree of relevance can be filtered out, thereby improving the relevance between the subgraph and the topic.
[0053] Of course, the knowledge graph of poetry creation can also be composed of multiple subgraphs, with each topic word corresponding to a subgraph. The subgraph corresponding to the topic word can be directly searched from the knowledge graph of poetry creation. This invention does not limit the method of searching for the subgraph corresponding to the topic word from the knowledge graph of poetry creation.
[0054] S103. Construct a training model, which includes a graph feature extractor to be trained, a pre-trained topic feature extractor, and a pre-trained poem feature extractor.
[0055] The training model is used to train a graph feature extractor to extract features related to topic words and poem samples from subgraphs. The topic feature extractor is a word-level feature extractor that can extract topic features; the poem feature extractor is a sentence-level feature extractor that can extract poem features. Both the topic feature extractor and the poem feature extractor can be trained using text feature extraction models such as BERT (Bidirectional Encoder Representation from Transformers) or BiLSTM (Bi-directional Long Short-Term Memory).
[0056] like Figure 5 The diagram shown is a structural schematic of the training model in this embodiment, wherein the output layers of the graph feature extractor 31, the topic feature extractor 32, and the poem feature extractor 33 are connected to the output layer 34 of the training model 3.
[0057] S104. Input the sub-map into the graph feature extractor, input the topic words into the topic feature extractor, and input the poem sample into the poem feature extractor to output feature vectors in the output layer of the trained model.
[0058] like Figure 5 As shown, after inputting sub-graph 41 into graph feature extractor 31, graph feature extractor 31 outputs a vector matrix representing the graph features of sub-graph 41; after inputting topic words 42 into topic feature extractor 32, topic feature extractor 32 outputs a vector matrix representing the topic features of topic words 42; after inputting poem sample 43 into poem feature extractor 33, poem feature extractor 33 outputs a vector matrix representing the poem features of poem sample 43. Finally, the vector matrices representing graph features, topic features, and poem features can be merged and output as feature vectors at the output layer of training model 3. For example, the vector matrix D1 representing graph features, the vector matrix D2 representing topic features, and the vector matrix D3 representing poem features are concatenated into a feature vector (D1+D2+D3)M. Since this embodiment is used to train a graph feature extractor, the output feature vector can also be only a vector matrix representing graph features. It should be noted that the sub-graph input to the graph feature extractor is a directed unweighted graph.
[0059] S105. Adjust the parameters of the graph feature extractor based on the feature vector.
[0060] The parameters of the graph feature extractor are adjusted based on the feature vectors. A standard vector for the feature vectors can be preset, and the vector difference between the feature vectors and the standard vectors is calculated. If the magnitude of this vector difference is greater than a preset threshold, the parameters of the graph feature extractor are adjusted accordingly until the magnitude of the vector difference is less than the preset threshold. Training of the graph feature extractor then stops, resulting in a trained graph feature extractor. The trained graph feature extractor can extract graph features related to the keywords and poem samples. That is, the graph feature extractor does not extract features from all nodes in the subgraph, but only the features of nodes related to the keywords and poem samples.
[0061] In an optional embodiment of the present invention, adjusting the parameters of the graph feature extractor based on the feature vector includes: determining the classification of the graph features extracted by the graph feature extractor from the sub-graph based on the feature vector, the classification including graph features related to topic words and poem samples, and graph features not related to topic words and poem samples; calculating the loss rate based on the classification and a preset loss function; determining whether the loss rate is less than a preset loss rate threshold; if yes, stopping the training of the graph feature extractor in the training model to obtain a trained graph feature extractor; if no, adjusting the parameters of the graph feature extractor based on the loss rate, and returning to the step of inputting the sub-graph into the graph feature extractor, the topic words into the topic feature extractor, and the poem samples into the poem feature extractor to output feature vectors at the output layer of the training model.
[0062] The preset loss function can be the cross-entropy loss function.
[0063] In this embodiment, a binary classification task is set up to train the graph feature extractor. The graph feature extractor learns to extract graph features related to the topic words and poem samples from the sub-graph. For example, when the topic word is "pastoral scenery" and the poem is "the mountain air is beautiful at sunset", if the intention words corresponding to the extracted graph features are "jade rabbit" or "birds flying wing to wing", then the graph features are not related to the topic words and poem samples. If the intention words corresponding to the graph features are "flying birds" or "southern mountain", then the graph features are related to the topic words and poem samples. Through the above training, the graph feature extractor can be equipped with the ability to extract graph features related to the topic words and poem samples from the sub-graph.
[0064] In one example of this embodiment, an imagery word prediction task and a context and coherence learning task can also be set to train the graph feature extractor's ability to use imagery words and learn context and coherence. Specifically, first, topic words, poem samples related to the topic words, and sub-graphs are acquired. Words representing imagery words in the poem samples are masked. Then, the poem samples with masked imagery words are input into the poem feature extractor, the sub-graphs are input into the graph feature extractor, and the topic words are input into the topic feature extractor, thereby adjusting the parameters of the graph feature extractor. For example, as... Figure 5As shown, when the keyword is "missing one's hometown", the "bright moon" in the original poem sample is masked, resulting in the poem sample "Raising my head, I gaze; lowering my head, I think of my hometown". The training graph feature extractor extracts graph features representing image words (nodes) related to the keyword and the poem sample from the sub-graph related to the keyword. The keyword is "missing one's hometown", meaning that the image words corresponding to the extracted graph features can be "bright moon" or words with similar meanings to "bright moon", such as the alternative name for "bright moon", "jade rabbit". Although "wanderer" also has the meaning of homesickness, it makes the context of the poem sample inconsistent and does not conform to semantic coherence. Therefore, the graph feature extractor will not extract the image word "wanderer" from the sub-graph to generate graph features.
[0065] In the contextual and coherence learning task, it can also be regarded as a binary classification task. In the training data, positive examples can be two consecutive lines of poetry extracted from poems, such as "I raise my head to gaze at the bright moon, I lower my head to think of my hometown", or two lines with the same meaning and no conflict: "I raise my head to gaze at the bright moon, the wild geese return to Luoyang". Negative examples are two lines of poetry randomly combined in different contexts, such as "I raise my head to gaze at the bright moon, I climb to a higher level".
[0066] After training, we obtain graph features that can extract keywords and poem samples. At the same time, the image words corresponding to the obtained graph features meet the contextual similarity and semantic coherence of the upper and lower sentences, so that the image words corresponding to the graph features can be integrated with the context of the poem and make the upper and lower sentences of the poem coherent. This makes the generated poems more in line with the standards of human poetry creation and improves the quality of poetry creation. For the specific training process, you can refer to the above training process of adjusting the parameters of the graph feature extractor.
[0067] The graph feature extractor training method of this invention first acquires training data, which includes topic words and poem samples. Based on the topic words, it searches for sub-graphs matching the topic words in the poetry creation knowledge graph. Since the poetry creation knowledge graph includes imagery words, the sub-graphs also include imagery words. A training model is constructed, comprising a graph feature extractor to be trained, a pre-trained topic feature extractor, and a pre-trained poem sample feature extractor. The output layers of the graph feature extractor, topic feature extractor, and poem sample feature extractor are connected to the output layer of the training model. The training model is used to train the graph feature extractor to extract features related to topic words and poem samples from the sub-graphs. The sub-graphs are input into the graph feature extractor, the topic words are input into the topic feature extractor, and the poem samples are input into the poem sample feature extractor to output feature vectors at the output layer of the training model. The parameters of the graph feature extractor are adjusted based on the feature vectors. By employing a topic feature extractor and a poem feature extractor in conjunction with a trained graph feature extractor, the graph feature extractor can extract graph features related to topic words and poem samples from sub-graphs. Since the sub-graphs also include imagery words, the graph features also include imagery word features related to topic words and poem samples. In other words, the trained graph feature extractor can flexibly extract imagery word features from the sub-graphs. When generating poems, if the sub-graphs are input into a pre-trained poem generation model, the poem generation model can generate poems with artistic conception based on the imagery word features in the sub-graphs, thus realizing the flexible use of imagery words to generate poems with artistic conception.
[0068] Example 2
[0069] Figure 6 This is a flowchart of a poetry generation method provided in Embodiment 2 of the present invention. This embodiment is applicable to situations where poetry is automatically generated using input data. The method can be executed by a computer used to generate poetry, and the computer can be configured in an electronic device. Figure 6 As shown, the training method for this graph feature extractor includes:
[0070] S601. Obtain the input data required for poetry generation. The input data includes keywords.
[0071] The input data can be manually entered data. The theme is the guiding direction for creating poems. When creating poems, they are usually generated based on a certain theme. The theme words are words that correspond to the theme.
[0072] S602. Based on the theme word, search for the sub-graph in the poetry creation knowledge graph that matches the theme word. The poetry creation knowledge graph includes image words.
[0073] An image is an objective image used to convey subjective emotions when creating poems, and it is also the main body that enables poems to have artistic conceptions. An image word is the name of the image. For example, the bright moon can be used to convey homesickness, so the word "bright moon" can be used as an image word.
[0074] The knowledge graph for poem creation includes multiple nodes and the attributes between adjacent nodes. Each node corresponds to a word, and the attributes between adjacent nodes are the attributes between the words corresponding to adjacent nodes. For example, Figure 2 As shown in the poem creation word spectrum of this embodiment, the attribute between "lovesickness" and "missing" is "belonging to", indicating that "lovesickness" belongs to "missing", and the attribute between "wild geese" and "lovesickness" is "implies", indicating that "wild geese" implies "lovesickness". For poem creation, the words corresponding to the nodes include the theme words and the image words corresponding to the theme words.
[0075] Searching for a sub-graph that matches the theme word from the knowledge graph for poem creation is to extract a sub-graph from the knowledge graph for poem creation that contains the image words related to the theme word. The node with the most similar semantics to the theme word can be searched as the root node from the knowledge graph for poem creation, and then the nodes adjacent to the root node are searched. A sub-graph is formed according to the root node, the nodes adjacent to the root node, and the attributes between the nodes.
[0076] S603. Input the input data and the sub-graph into a pre-trained poem generation model to generate a poem in the poem generation model. The sub-graph is input into the graph feature extractor of the poem generation model.
[0077] Among them, the graph feature extractor is trained by the graph feature extractor training method in Embodiment 1. The graph feature extractor can be used as a pre-stage input in the poem generation model. Then the graph feature extractor can extract the graph features of the image words related to the input data from the sub-graph. When the input data is the theme word, the graph features of the related image words can be extracted from the sub-graph. The poem generation model can use this graph feature to obtain the corresponding image word and apply this image word to generate a poem related to the input data and with artistic conception.
[0078] In an optional embodiment of the present invention, the poem generation model further includes a poem line feature extractor and a theme feature extractor. The input data further includes existing poem lines. Inputting the input data and the sub-graph into a pre-trained poem generation model to generate a poem in the poem generation model includes:
[0079] Input the theme word into the theme feature extractor of the pre-trained poem generation model, input the existing poem lines into the poem line feature extractor of the poem generation model, and input the sub-graph into the graph feature extractor of the poem generation model to generate the next poem line of the existing poem lines in the poem generation model.
[0080] The topic feature extractor, the poem line feature extractor, and the graph feature extractor can serve as pre-processing inputs in the poetry generation model. The poetry generation model can be trained using a generative adversarial network. Specifically, during training, the next line of poetry generated by the model can be classified: one category is that the generated next line is related to the previous line, and the other category is that the generated next line is not related to the previous line.
[0081] In the training process of the graph feature extractor in Example 1, the preceding and following lines of poetry can also be used as poetry samples to train the graph feature extractor. The graph feature extractor can then learn the contextual similarity and semantic coherence of the preceding and following lines. Therefore, by inputting the topic words into the topic feature extractor of the pre-trained poetry generation model, inputting the existing poetry lines into the poetry line feature extractor of the poetry generation model, and inputting the sub-graph into the graph feature extractor of the poetry generation model, the poetry generation model can generate the next line of poetry of the existing poetry lines. The next line of poetry is similar in context and semantically coherent with the previous line of poetry.
[0082] In an optional embodiment of the present invention, the poetry generation model is trained in the following manner:
[0083] Acquire training data, which includes topic words, sub-graphs matching the topic words, and poem samples related to the topic words. Initialize the poem generation model, which includes a pre-trained graph feature extractor, topic feature extractor, poem sample feature extractor, and generator. The input layer of the generator is connected to the output layers of the graph feature extractor, topic feature extractor, and poem sample feature extractor, respectively. Randomly extract topic words, sub-graphs matching the topic words, and poem samples related to the topic words and input them into the topic feature extractor, graph feature extractor, and poem sample feature extractor, respectively, to output the next predicted poem sample. Calculate the loss rate based on the poem sample and the predicted poem. If the loss rate is less than a preset loss rate threshold, adjust the generator parameters according to the loss rate and return to the steps of randomly extracting topic words, sub-graphs matching the topic words, and poem samples related to the topic words and inputting them into the topic feature extractor, graph feature extractor, and poem sample feature extractor, respectively.
[0084] The pre-trained graph feature extractor, topic feature extractor, and poem feature extractor serve as the pre-level input to the poetry generation model. They extract topic features, graph features, and poem sample features, which are then input into the generator. The generator generates the next predicted poem based on these parameters. The topic features, graph features, and poem sample features include features of imagery words. Since the predicted poem is generated based on these features, it can also possess imagery. In one example of the above embodiment, the loss rate is calculated based on the poem sample and the predicted poem, including:
[0085] Calculate the loss rate using the following formula:
[0086]
[0087] Among them, D peom (N p N b (N) represents the difference in artistic conception between the sample poem and the predicted poem, i.e., the loss rate, where N is the total set of nodes in the sub-graph that match the topic keywords. p With N b Let be the set of nodes in the subgraph containing the words in the sample and predicted poem lines, respectively. The Num(·) function is used to count the number of nodes in the set. ij d represents the length of the shortest path between node i and node j in the subgraph. lm α represents the length of the shortest path between each node in the subgraph and each node in the overall set of the predicted poem, where α is a hyperparameter.
[0088] In the formula for calculating the loss rate, the first half measures the difference in mood between the sample poem and the predicted poem, aiming to control the semantic coherence between the poems. The second half measures the difference between the predicted poem and the keyword, aiming to control the relevance between the generated poem and the keyword. The hyperparameter α is used to balance the influence of the two parts on the measurement of the difference in mood, and can be adjusted according to actual needs. By calculating the loss rate using this formula, the measurement of the difference in mood between the two lines of the poem can be controlled.
[0089] This embodiment of the poetry generation method involves acquiring input data required for poetry generation, including topic words; searching for sub-graphs matching the topic words from a poetry creation knowledge graph, which includes imagery words; inputting the input data and sub-graphs into a pre-trained poetry generation model to generate poetry; and inputting the sub-graphs into the graph feature extractor of the poetry generation model. The graph feature extractor is trained using a graph feature extractor training method described in Embodiment 1, allowing it to extract graph features of imagery words related to the input data. The poetry generation model can then generate poetry with evocative imagery based on these graph features. Furthermore, the graph feature extractor can learn about contextual similarity and semantic coherence between sentences. When the poetry generation model generates a predicted poem, the predicted poem is contextually similar to and semantically coherent with existing poem samples.
[0090] Example 3
[0091] Figure 7A schematic diagram of an electronic device 70 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0092] like Figure 7 As shown, the electronic device 70 includes at least one processor 71 and a memory, such as a read-only memory (ROM) 72 and a random access memory (RAM) 73, communicatively connected to the at least one processor 71. The memory stores computer programs executable by the at least one processor. The processor 71 can perform various appropriate actions and processes based on the computer program stored in the ROM 72 or loaded from storage unit 78 into the RAM 73. The RAM 73 can also store various programs and data required for the operation of the electronic device 70. The processor 71, ROM 72, and RAM 73 are interconnected via a bus 74. An input / output (I / O) interface 75 is also connected to the bus 74.
[0093] Multiple components in electronic device 70 are connected to I / O interface 75, including: input unit 76, such as keyboard, mouse, etc.; output unit 77, such as various types of monitors, speakers, etc.; storage unit 78, such as disk, optical disk, etc.; and communication unit 79, such as network card, modem, wireless transceiver, etc. Communication unit 79 allows electronic device 70 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0094] Processor 71 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 71 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 71 performs the various methods and processes described above, such as graph feature extractor training methods, and / or, poetry generation methods.
[0095] In some embodiments, the graph feature extractor training method and / or the poetry generation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 78. In some embodiments, part or all of the computer program may be loaded into and / or installed on electronic device 70 via ROM 72 and / or communication unit 79. When the computer program is loaded into RAM 73 and executed by processor 71, one or more steps of the graph feature extractor training method and / or the poetry generation method described above may be performed. Alternatively, in other embodiments, processor 71 may be configured to execute the graph feature extractor training method and / or the poetry generation method by any other suitable means (e.g., by means of firmware).
[0096] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0097] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0098] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0099] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0100] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0101] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0102] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0103] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for training a graph feature extractor, characterized in that, include: Acquire training data, which includes keywords and sample poems; Based on the stated theme, search for sub-graphs matching the stated theme from the knowledge graph of poetry creation, wherein the knowledge graph of poetry creation includes imagery words; A training model is constructed, comprising a graph feature extractor to be trained, a pre-trained topic feature extractor, and a pre-trained poem feature extractor. The output layers of the graph feature extractor, the topic feature extractor, and the poem feature extractor are connected to the output layer of the training model. The training model is used to train the graph feature extractor to extract graph features related to the topic words and the poem samples from the sub-graph based on a binary classification task. The classification includes cases where the graph features are related to the topic words and the poem samples, and cases where the graph features are not related to the topic words and the poem samples. The sub-graph is input into the graph feature extractor, the topic words are input into the topic feature extractor, and the poem samples are input into the poem feature extractor, so as to output feature vectors in the output layer of the training model; The parameters of the graph feature extractor are adjusted based on the feature vector.
2. The graph feature extractor training method as described in claim 1, characterized in that, The poetry creation knowledge graph includes multiple nodes and attributes between adjacent nodes. The step of searching for a subgraph matching the theme word from the poetry creation knowledge graph includes: Find the node in the knowledge graph of poetry creation that is most semantically similar to the topic word and use it as the root node; Calculate the path length from each node in the knowledge graph to the root node based on the attributes of two adjacent nodes in the poetry creation knowledge graph; Nodes whose path length is less than a preset length threshold are identified as target nodes, and a sub-graph matching the topic word is obtained.
3. The graph feature extractor training method as described in claim 2, characterized in that, The step of calculating the path length from each node in the knowledge graph to the root node based on the attributes of two adjacent nodes in the poetry creation knowledge graph includes: For each node in the poetry creation knowledge graph, determine the shortest path between the node and the root node; Count the number of paths in the shortest path whose attributes are preset attributes, and calculate the product of the number of paths and the penalty factor; Calculate the sum of the length of the shortest path and the product of the two, and use this sum as the path length from the node to the root node.
4. The graph feature extractor training method according to any one of claims 1-3, characterized in that, The step of adjusting the parameters of the graph feature extractor based on the feature vector includes: The graph feature extractor determines the classification of the graph features extracted from the sub-graph based on the feature vector. The classification includes graph features that are related to the topic words and the poem samples, and graph features that are not related to the topic words and the poem samples. Calculate the loss rate based on the classification and the preset loss function; Determine whether the loss rate is less than a preset loss rate threshold; If so, stop training the graph feature extractor in the training model to obtain the trained graph feature extractor; If not, adjust the parameters of the graph feature extractor according to the loss rate, and return to the step of inputting the sub-graph into the graph feature extractor, the topic words into the topic feature extractor, and the poem sample into the poem feature extractor, so as to output a feature vector in the output layer of the training model.
5. A method for generating poetry, characterized in that, include: Obtain the input data required for poetry generation, including keywords; Based on the stated theme, search for sub-graphs matching the stated theme from the knowledge graph of poetry creation, wherein the knowledge graph of poetry creation includes imagery words; The input data and the sub-graph are input into a pre-trained poetry generation model to generate poems, and the sub-graph is input into the graph feature extractor of the poetry generation model. The graph feature extractor is trained using the graph feature extractor training method according to any one of claims 1-4.
6. The method for generating poetry as described in claim 5, characterized in that, The poetry generation model further includes a pre-trained poem feature extractor and a topic feature extractor. The input data also includes existing poems. The step of inputting the input data and the sub-map into the pre-trained poetry generation model to generate poems in the poetry generation model includes: The topic words are input into the topic feature extractor of the pre-trained poetry generation model, the existing verses are input into the verse feature extractor of the poetry generation model, and the sub-graph is input into the graph feature extractor of the poetry generation model, so as to generate the next verse of the existing verse in the poetry generation model.
7. The method for generating poetry as described in claim 5 or 6, characterized in that, The poetry generation model is trained in the following way: Acquire training data, which includes topic words, sub-graphs matching the topic words, and poetry samples related to the topic words; An initialization process is performed on a poetry generation model, which includes a pre-trained graph feature extractor, a topic feature extractor, a poem line feature extractor, and a generator. The input layer of the generator is connected to the output layers of the graph feature extractor, the topic feature extractor, and the poem line feature extractor, respectively. The topic words, the sub-graphs matching the topic words, and the poem samples related to the topic words are randomly extracted and input into the topic feature extractor, the graph feature extractor, and the poem feature extractor, respectively, to output the next predicted poem for the poem sample; The loss rate is calculated based on the sample poems and the predicted poems. When the loss rate is less than a preset loss rate threshold, the parameters of the generator are adjusted according to the loss rate, and the process of randomly extracting the topic word, the sub-graph matching the topic word, and the poem sample related to the topic word are respectively input into the topic feature extractor, the graph feature extractor, and the poem feature extractor.
8. The method for generating poetry as described in claim 7, characterized in that, The step of calculating the loss rate based on the poem sample and the predicted poem includes: Calculate the loss rate using the following formula: in, The loss rate between the sample poem and the predicted poem. To retrieve the total set of nodes in the sub-graph that match the stated topic term, and These are the sets of nodes in the sub-graph containing the words contained in the sample poem and the predicted poem, respectively. The function is used to count the number of nodes in a set. This represents the length of the shortest path between node i and node j in the subgraph. This represents the length of the shortest path between each node of the predicted poem in the sub-graph and each node in the overall set. This is a hyperparameter.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the graph feature extractor training method of any one of claims 1-4, and / or the poetry generation method of any one of claims 5-8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the graph feature extractor training method of any one of claims 1-4, and / or the poetry generation method of any one of claims 5-8.
Citation Information
Patent Citations
Deep learning-based poetry generation method and device, apparatus, and storage medium
CN110134968A
Ancient poem proposition method and system
CN111400506A