Search

CN-115599887-B - Graph feature extractor training method, poem generation method, equipment and storage medium

CN115599887BCN 115599887 BCN115599887 BCN 115599887BCN-115599887-B

Abstract

The invention discloses a graph feature extractor training method, a poem generating method, equipment and a storage medium, which are used for firstly acquiring a subject and a poem sample, searching a sub-graph matched with the subject from a poem creation knowledge graph according to the subject, wherein the sub-graph also comprises a image, constructing a training model, and adopting the subject feature extractor and the poem feature extractor to cooperate with the training graph feature extractor, so that the graph feature extractor can extract graph features related to the subject and the poem sample from the sub-graph, namely, the trained graph feature extractor can flexibly extract the image features from the sub-graph, and the poem generation model can generate poems with the image when the sub-graph is input into a pre-trained poem generation model, thereby realizing flexible use of the image to generate the poems.

Inventors

  • GAO JIE
  • XU TIANCI
  • SUN YAQIANG
  • ZHOU YI
  • HU SHENGJIE
  • ZHAO LIANGTIAN

Assignees

  • 芯跳科技(广州)有限公司

Dates

Publication Date
20260508
Application Date
20221025

Claims (10)

  1. 1. A graph feature extractor training method, comprising: acquiring training data, wherein the training data comprises a subject term and a poem sample; Searching a sub-graph matched with the subject word from a poetry creation knowledge graph according to the subject word, wherein the poetry creation knowledge graph comprises an image word; Constructing a training model, wherein the training model comprises a graph feature extractor to be trained, a trained theme feature extractor and a trained verse feature extractor, the graph feature extractor, the theme feature extractor and an output layer of the verse feature extractor are connected with an output layer of the training model, and the training model is used for training the graph feature extractor to extract graph features related to the subject matters and the verse samples from the sub-atlas based on a classification task, wherein classification comprises that the graph features are related to the subject matters and the verse samples, and the graph features are not related to the subject matters and the verse samples; Inputting the sub-graph into the graph feature extractor, inputting the subject term into the subject feature extractor, and inputting the verse sample into the verse feature extractor to output feature vectors at an output layer of the training model; and adjusting parameters of the graph feature extractor according to the feature vector.
  2. 2. The training method of the graph feature extractor of claim 1, wherein the poetry creation knowledge graph includes a plurality of nodes and attributes between neighboring nodes, the searching sub-graph matching the theme from the poetry creation knowledge graph according to the theme includes: searching a node which is most similar to the semantics of the subject term from the poetry creation knowledge graph as a root node; Calculating the path length from each node in the knowledge graph to the root node according to the attribute of two adjacent nodes in the poetry creation knowledge graph; and determining the node with the path length smaller than a preset length threshold as a target node to obtain a sub-graph matched with the subject term.
  3. 3. The training method of the graph feature extractor of claim 2, wherein the calculating the path length from each node to the root node in the knowledge-graph according to the attributes of two adjacent nodes in the poetry-authoring knowledge-graph comprises: determining the shortest path between each node in the poetry creation knowledge graph and the root node; counting the number of paths with the attribute of the shortest path being a preset attribute, and calculating the product of the number of paths and a penalty factor; A sum of the shortest path length and the product is calculated as a path length of the node to the root node.
  4. 4. A graph feature extractor training method as claimed in any one of claims 1 to 3, characterized in that the adjusting of parameters of the graph feature extractor in accordance with the feature vector comprises: determining a classification of the graph features extracted by the graph feature extractor from the sub-graph, the classification comprising that the graph features are related to the subject matter and the verse sample, and that the graph features are not related to the subject matter and the verse sample, from the feature vector; calculating a loss rate based on the classification and a preset loss function; Judging whether the loss rate is smaller than a preset loss rate threshold value or not; If yes, stopping training the graph feature extractor in the training model to obtain a trained graph feature extractor; If not, the parameters of the graph feature extractor are adjusted according to the loss rate, and the steps of inputting the sub-graph into the graph feature extractor, inputting the subject term into the subject feature extractor and inputting the verse sample into the verse feature extractor are returned to output feature vectors at the output layer of the training model.
  5. 5. A poem generation method, comprising: Acquiring input data required by poetry generation, wherein the input data comprises a subject term; Searching a sub-graph matched with the subject word from a poetry creation knowledge graph according to the subject word, wherein the poetry creation knowledge graph comprises an image word; Inputting the input data and the sub-graph into a pre-trained poetry generation model so as to generate poetry in the poetry generation model, and inputting the sub-graph into a graph feature extractor of the poetry generation model; Wherein the graph feature extractor is trained by the graph feature extractor training method of any of claims 1-4.
  6. 6. The poetry generation method of claim 5 wherein the poetry generation model further includes a trained poetry feature extractor and a theme feature extractor, the input data further includes an existing poetry, the inputting the input data and the sub-pattern into a pre-trained poetry generation model to generate a poetry in the poetry generation model includes: Inputting the subject term into a subject feature extractor of a pre-trained poem generation model, inputting the existing poem into a poem feature extractor of the poem generation model, and inputting the sub-pattern into a graph feature extractor of the poem generation model to generate a next poem of the existing poem in the poem generation model.
  7. 7. A poetry generating method according to claim 5 or 6, wherein the poetry generating model is trained by: Acquiring training data, wherein the training data comprises a subject term, a sub-graph matched with the subject term and a verse sample related to the subject term; Initializing a poetry generation model, wherein the poetry generation model comprises a trained graph feature extractor, a theme feature extractor, a poetry feature extractor and a generator, and an input layer of the generator is respectively connected with output layers of the graph feature extractor, the theme feature extractor and the poetry feature extractor; Randomly extracting the subject term, a sub-graph matched with the subject term and a verse sample related to the subject term, and respectively inputting the subject feature extractor, the graph feature extractor and the verse feature extractor to output a next predicted verse of the verse sample; Calculating a loss rate according to the poem sample and the predicted poem; And when the loss rate is smaller than a preset loss rate threshold, parameters of the generator are adjusted according to the loss rate, and the step of randomly extracting the subject term, the sub-pattern matched with the subject term and the poem sample related to the subject term is returned to be respectively input into the subject feature extractor, the graph feature extractor and the poem feature extractor.
  8. 8. A verse generating method according to claim 7, wherein said calculating a loss rate from said verse sample and said predicted verse comprises: The loss rate is calculated according to the following formula: Wherein, the For the loss rate of the verse sample and the predicted verse, To retrieve a total set of nodes in the sub-graph matching the subject term from the subject term, And (3) with Respectively, the set of nodes in the sub-graph of the phrase sample and the words contained in the predicted phrase, The function is a function of the number of nodes in the statistical set, Representing the length of the shortest path between node i and node j in the sub-graph, Representing the length of the shortest path of each node in the sub-graph of the predicted verse to each node in the total set, Is a super parameter.
  9. 9. An electronic device, the electronic device comprising: At least one processor, and A memory communicatively coupled to the at least one processor, wherein, The memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the graph feature extractor training method of any of claims 1-4 and/or the poetry generation method of any of claims 5-8.
  10. 10. A computer readable storage medium storing computer instructions for causing a processor to implement 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 when executed.

Description

Graph feature extractor training method, poem generation method, equipment and storage medium Technical Field The present invention relates to the field of natural language processing technologies, and in particular, to a graph feature extractor training method, a poem generating device, and a storage medium. Background Classical poems are the top-quality products of traditional culture and are the coagulants of Chinese ethnic spirit culture, the current Chinese poem generation technology has achieved better results, and the poems generated by various poem generation models are various in style, and simultaneously antithesis is neat and flat and rhyme. However, the conventional poetry generating model has the problem that the ideas cannot be flexibly used when generating the poetry, and the ideas play a very important role in the poetry no matter how the poetry is in the scene or the written note, and meanwhile, the ideas are the basis for forming the mood, and the ideas cannot be flexibly used, so that the automatically generated poetry lacks the mood. Disclosure of Invention The invention provides a training method of a graph feature extractor, a poetry generating method, equipment and a storage medium, which are used for solving the problems that the conventional Chinese poetry generating model cannot flexibly use the ideas when generating the poetry, and the automatically generated poetry lacks the mood. In a first aspect, the present invention provides a graph feature extractor training method, including: acquiring training data, wherein the training data comprises a subject term and a poem sample; Searching a sub-graph matched with the subject word from a poetry creation knowledge graph according to the subject word, wherein the poetry creation knowledge graph comprises an image word; Building a training model, wherein the training model comprises a graph feature extractor to be trained, a trained theme feature extractor and a trained verse feature extractor, the graph feature extractor, the theme feature extractor and an output layer of the verse feature extractor are connected with an output layer of the training model, and the training model is used for training the graph feature extractor to extract features related to the subject words and the verse samples from the sub-atlas; inputting the sub-graph into the graph feature extractor, inputting the subject term into the subject feature extractor, and inputting the verse sample into the verse extractor to output a feature vector at an output layer of the training model; and adjusting parameters of the graph feature extractor according to the feature vector. In a second aspect, the present invention provides a poem generating method, including: Acquiring input data required by poetry generation, wherein the input data comprises a subject term; Searching a sub-graph matched with the subject word from a poetry creation knowledge graph according to the subject word, wherein the poetry creation knowledge graph comprises an image word; Inputting the input data and the sub-graph into a pre-trained poetry generation model so as to generate poetry in the poetry generation model, and inputting the sub-graph into a graph feature extractor of the poetry generation model; Wherein the graph feature extractor is trained by the graph feature extractor training method of the first aspect. In a third aspect, the present invention provides an electronic device, including: At least one processor, and A memory communicatively coupled to the at least one processor, wherein, The memory stores a computer program executable 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. In a fourth aspect, the present invention provides a computer readable storage medium storing computer instructions for causing a processor to implement the graph feature extractor training method according to the first aspect of the present invention and/or the poetry generation method according to the second aspect. The training method of the graph feature extractor comprises the steps of firstly obtaining training data, wherein the training data comprise subject words and poem samples, searching sub-graphs matched with the subject words from a poem creation knowledge graph according to the subject words, inputting the subject words into the subject feature extractor and inputting the poem samples into the poem feature extractor, constructing a training model, wherein the training model comprises a graph feature extractor to be trained, a trained subject feature extractor and a trained poem feature extractor, an output layer of the graph feature extractor, the subject feature extractor and the poem feature extractor is connected with an output layer of the training model, the training model is used for training the graph feature e