An interactive poem writing system and method based on a large language model and a knowledge graph

An interactive poetry writing system based on a large language model and knowledge graph is used to create user emotional profiles, recommend imagery, and assist users in completing poetry creation. This solves the problem that existing models cannot involve users and enables emotional expression and creative assistance.

CN119337839BActive Publication Date: 2025-10-24SICHUAN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411465277.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2025-10-24
Estimated Expiration
2044-10-21

AI Technical Summary

Technical Problem

Existing poetry generation models cannot achieve user participation, and poetry knowledge graphs lack emotion, theme, and imagery information, making it difficult for users to express their emotions and complete their creations.

Method used

An interactive poetry writing system based on a large language model and knowledge graph establishes user emotional profiles and recommends matching images to assist users in creating poems through a multi-dimensional poetry knowledge graph and interactive poetry writing system.

Benefits of technology

It reduces the difficulty of poetry creation, allowing users to express their emotions during the interaction process and complete the creation with the help of the system's modification suggestions and sentence completion, thus reducing the cost and difficulty of creation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119337839B_ABST
    Figure CN119337839B_ABST
Patent Text Reader

Abstract

The application discloses an interactive poem writing system and method based on a large language model and a knowledge graph, and the system comprises a preprocessing module, a sentiment extraction module, an image extraction module, a theme extraction module, a sentiment preset module and an interactive poem writing module. The method comprises the following steps: S1, removing data that does not contain appreciation in a poem data set; S2, extracting and mapping sentiment information; S3, extracting a poem image; S4, extracting and mapping theme information; S5, establishing a multi-dimensional poem knowledge graph by comprehensively integrating sentiment information, a poem image and theme information; S6, establishing a user's sentiment portrait based on a user interaction history; and S7, performing interactive auxiliary poem writing creation based on the user's sentiment portrait. The multi-dimensional poem knowledge graph of the interactive poem writing system comprises sentiment, theme and image information, and the user can complete the creation through interaction, so that the difficulty of writing poems is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing technology, and in particular to an interactive poetry writing system and method based on a large language model and a knowledge graph. Background Art

[0002] For most people, poetry creation presents a high barrier to entry, as the process requires a deep understanding of poem structure, rhythm, symbolism, and linguistic expression, which is particularly challenging without training and experience. However, with advances in artificial intelligence (AI), numerous poetry generation models have emerged that can assist the general public in creating complete poems. These models typically use a corpus of classical poetry labeled with sentiment and style as training data. Once trained, users simply input imagery, sentiment, or style, and the model automatically generates a complete poem.

[0003] However, existing poetry generation models can only directly generate a complete poem, ignoring user participation and preventing users from expressing their emotions in the process. Existing open-source poetry knowledge graphs do not simultaneously include sentiment, theme, and imagery information. Furthermore, poetic imagery extraction suffers from poor word segmentation and difficulty selecting imagery words. Summary of the Invention

[0004] In order to solve the problems that existing poetry generation models can only directly generate complete poems while ignoring user participation and that poetry knowledge graphs do not contain emotion, theme and image information at the same time, the present invention proposes an interactive poetry writing system and method based on a large language model and a knowledge graph. The system aims to establish a user emotion profile through interaction between the user and the system, recommend matching images, and assist the user in completing the creation. A multi-dimensional poetry knowledge graph with improved image extraction is proposed to solve the above problems.

[0005] This application discloses an interactive poetry writing system based on a large language model and a knowledge graph, including a multi-dimensional poetry knowledge graph and an interactive poetry writing system;

[0006] The multi-dimensional poetry knowledge graph includes:

[0007] Preprocessing module, used to remove poetry data that does not contain appreciation and format poetry data into JSON;

[0008] Emotion extraction module, used to extract emotional information from poetry appreciation and map it to preset emotional nodes;

[0009] Image extraction module, used to extract images from poems and use them as image nodes of poems;

[0010] Theme extraction module, used to extract theme information from poetry appreciation and map it to preset theme nodes;

[0011] The interactive poem writing system comprises:

[0012] An emotion preset module configured to determine an emotional portrait of a user by searching for relevant nodes in a multi-dimensional poem knowledge graph according to a history of interaction of the user with the system;

[0013] An interactive poem writing module configured to provide the user with modification suggestions, complete the poem and ask about the emotional state to iterate the emotional portrait of the user according to the state of the poem and the emotional portrait of the user, thereby helping the user to complete the poem writing.

[0014] The application also discloses an interactive poem writing method based on a large language model and a knowledge graph, comprising the following steps:

[0015] S1, obtaining a poem data set and removing data in the poem data set that does not contain appreciation;

[0016] S2, extracting and mapping emotional information from poem appreciation based on a large language model and a text embedding model;

[0017] S3, extracting poem images from poems by multivariate linear regression;

[0018] S4, extracting and mapping theme information from poem appreciation using a large language model;

[0019] S5, establishing a multi-dimensional poem knowledge graph by integrating emotional information, poem images and theme information;

[0020] S6, establishing an emotional portrait of a user based on a history of user interaction;

[0021] S7, interactive auxiliary poem writing creation based on the emotional portrait of the user.

[0022] Preferably, the S1 comprises the following steps:

[0023] S11, collecting a poem data set composed of information such as ancient poetry and prose authors, appreciation, annotation, comment and the like from the network;

[0024] S12, removing poem data in the poem data set that does not contain an appreciation field;

[0025] S13, formatting poem data in the poem data set obtained in S12 in JOSN format.

[0026] Preferably, the S2 comprises the following steps:

[0027] S21, inputting poem appreciation of each piece of poem data in the poem data set into a large language model;

[0028] S22, outputting emotions expressed by poets in poems by the large language model;

[0029] S23, inputting the emotional input obtained in S22 into the acge-text-embedding text embedding model, converting the text representation of the emotion into a numerical vector representation, obtaining a first emotional vector, and performing standardization;

[0030] S24, inputting a plurality of preset 23 kinds of emotions (sorrow, pain, desolation, loneliness, indignation, magnanimity, simplicity, optimism, longing, love, missing, melancholy, misery, regret, admiration, sympathy, regret, disgust, reluctance, worry, joy, helplessness, praise) into the acge-text-embedding text embedding model, obtaining a plurality of second emotional vectors;

[0031] S25, performing cosine similarity calculation on the first emotional vector obtained in S23 and the plurality of second emotional vectors obtained in S24 respectively, and taking the preset emotional text corresponding to the highest cosine similarity as the emotional information of the poem.

[0032] Preferably, the S3 comprises the following steps:

[0033] S31, inputting the poem content in each piece of poem data into a large language model, and the large language model outputs the coarse segmentation result of the poem, simultaneously outputs a list of the same length in Boolean type, and labels whether the output word is a named entity;

[0034] S32, establishing a bi-gram model using the poem data set as a corpus, for a classical poem sentence with a length of n , it is considered that the current word is only related to the previous word, that is:

[0035]

[0036] According to Bayes' theorem, we have:

[0037]

[0038] According to the law of large numbers, use to approximate , that is:

[0039]

[0040] wherein, represents the frequency of the phrase or word in the corpus, represents the probability, is the i-th word;

[0041] S33, for the poem sentence without named entity, simply noted as and two segmentation modes, if the output word does not affect the selection of the segmentation mode, then directly merge, otherwise, take the segmentation mode as:

[0042]

[0043] wherein, represents the conditional probability approximated by the bi-gram model under the word segmentation mode, represents the word segmentation mode represented by "2 / 2 / 1", represents the word segmentation mode represented by "2 / 1 / 2", is the optimal word segmentation mode;

[0044] For the poem with a named entity, the part excluding the named entity is traversed in all word segmentation modes of the poem without the named entity, and the word segmentation mode with the maximum likelihood function value is selected ;

[0045] S34, after obtaining the word segmentation results of all poems, input the word segmentation results into a large language model, and the large language model outputs a list of Boolean types, indicating whether each word is a noun excluding named entities, if so, the noun is retained as a poem image candidate word;

[0046] S35, using the TF-IDF algorithm on all word segmentation results, calculate the TF-IDF value, the calculation formula is as follows:

[0047]

[0048] wherein, represents the frequency of the image candidate word w appearing in the poem s, represents the inverse document frequency of the image candidate word w in the entire corpus S, The calculation formula is:

[0049]

[0050] After obtaining the TF-ID value of all image candidate words, perform normalization processing;

[0051] S36, taking all image candidate words as nodes, and the co-occurrence relationship in the same poem as edges, construct an image candidate word graph , then the score iteration formula of each image candidate word is:

[0052]

[0053] is a node in , is a node in , is a node in , is a node in , is a node in , the cosine similarity of the two word vectors,​ representing the first iteration;

[0054] converge to all node scores according to the score iteration formula;

[0055] S37, after obtaining the TF-IDF value and TextRank score of each image candidate word respectively,

[0056] Obtain the CCPC dataset, which contains ancient poems and four keywords corresponding to each ancient poem. The four keywords are approximately regarded as images. The intersection of the image candidate words in each poem and the four keywords is taken as a positive sample, and the label is 1. Otherwise, it is a negative sample, and the label is -1. Set the loss function as HingeLoss for multivariate linear regression analysis. The specific calculation method is:

[0057]

[0058] wherein, is a weight vector, is a score vector of the training sample, is the label corresponding to the training sample, denotes transposition;

[0059] After obtaining the optimal weight of the TF-IDF value and TextRank score of the image candidate word using the gradient descent method, the total score of any image candidate word of each poem is calculated using weighted average, and the image candidate word with the highest score is obtained as the image.

[0060] Preferably, the S4 comprises the following steps:

[0061] Input the poem appreciation of each poem data in the poem data set into the large language model. According to the prompt word, the large language model outputs a list of 9 themes (mountain and water, battlefield and military, history and mythology, object and aspiration, farewell and love, travel and hometown, love and grievances, mourning and country, demotion and exile, other themes) corresponding to the theme of the poem in the format of “The theme of this poem is: <theme>” according to the prompt word. The theme is taken as the theme information of the poem.

[0062] Preferably, the S5 comprises the following steps:

[0063] Establish a knowledge graph node and a knowledge graph relationship. The knowledge graph node includes a poet node, a poem title node, a poem node, an emotion node, an image node, and a theme node.

[0064] ​​The knowledge graph nodes and knowledge graph relationships are imported into a Neo4j graph database as a knowledge graph using a py2neo library, thereby obtaining a multi-dimensional poem knowledge graph.

[0065] Preferably, the S6 comprises the following steps:

[0066] According to the interaction history of the user with the interactive poem composing system, theme nodes and emotion nodes within two hops in the multi-dimensional poem knowledge graph are searched, the theme node and the emotion node with the highest frequency are taken as the user's preferred theme and the current emotion state, thereby establishing the user's emotion portrait, and according to the user's preferred theme and the current emotion state, images within two hops in the multi-dimensional poem knowledge graph are searched and randomly pushed to the user as poem materials.

[0067] Preferably, the S8 comprises the following steps:

[0068] The poem composing state of the user is divided into three types, namely, an unfinished state of unfinished one sentence, a stage completion state of one to three sentences, and a completion state of all sentences;

[0069] Different interaction modes are set for the three poem composing states to help the user complete the poem composition.

[0070] Preferably, the interaction mode of the unfinished state comprises:

[0071] Fuzzy search is performed on the poem composed by the user using a fuzzywuzzy library, and the image nodes connected to the poem sentence node with the highest similarity are pushed to the user; if the user is in the unfinished state within a time threshold, the poem composed by the user is input into a large language model, the large language model outputs the completed poem and the corresponding reason, and the user can choose whether to accept or not;

[0072] The interaction mode of the stage completion state comprises:

[0073] The poem composed by the user and the preset emotion are input into a large language model, and it is judged which one of the preset emotions the current emotion state belongs to; if it does not match the emotion state in the user's emotion portrait, the current emotion state of the user is inquired, the user's emotion portrait is updated, otherwise, images are pushed to the user according to the user's emotion portrait;

[0074] The interaction mode of the completion state comprises:

[0075] The poem composed by the user is input into a large language model, the large language model outputs a list of modification suggestions, each element in the list includes the specific content of the modification suggestion, the modification content is extracted using a regular expression and matched with specific poem sentences, the modification suggestions corresponding to the poem sentences are displayed to the user in order, and the user can choose whether to accept the modification suggestions or not to complete the poem composition.

[0076] Advantages of the present application:

[0077] (1) The interactive poem writing system proposed by the application creates poems in the form of collage poems, reduces the difficulty of writing poems, and uses large language models to propose modification suggestions and complete poem sentences to assist users in completing the creation and expressing emotions in the interactive process, greatly reducing the cost and difficulty of poem creation.

[0078] (2) The interactive poem writing system proposed by the application establishes a user emotional portrait through user interaction with the system, recommends matching images to assist users in completing the creation and expressing emotions.

[0079] (3) The application proposes an improved multi-dimensional poem knowledge graph for image extraction, and finally establishes a multi-dimensional poem knowledge graph containing 26552 nodes and 85477 relationships. The multi-dimensional poem knowledge graph contains emotional, thematic and image information. BRIEF DESCRIPTION OF DRAWINGS

[0080] Figure 1 A composition diagram of the interactive poem writing system based on a large language model and a knowledge graph according to an embodiment of the application;

[0081] Figure 2 A flowchart of the multi-dimensional poem knowledge graph construction according to an embodiment of the application;

[0082] Figure 3 A flowchart of the image extraction method according to an embodiment of the application;

[0083] Figure 4 A subgraph in the multi-dimensional poem knowledge graph according to an embodiment of the application;

[0084] Figure 5 A flowchart of the interactive poem writing method according to an embodiment of the application;

[0085] Figure 6 A diagram of three poem writing states according to an embodiment of the application. DETAILED DESCRIPTION

[0086] To make the purpose, technical solutions and advantages of the present application clearer and more apparent, the following embodiments are described with reference to the accompanying drawings.

[0087] One embodiment of the present application discloses an interactive poem writing system based on a large language model and a knowledge graph, as shown in Figure 1 The interactive poem writing system includes a multi-dimensional poem knowledge graph and an interactive poem writing system.

[0088] The multi-dimensional poem knowledge graph includes:

[0089] A preprocessing module for removing poetry data that does not contain appreciation and JSON formatting of poetry data;

[0090] An emotion extraction module for extracting emotion information from poetry appreciation and mapping to a preset emotion node;

[0091] An image extraction module for extracting images in the poem as image nodes of the poem;

[0092] A theme extraction module for extracting theme information from poetry appreciation and mapping to a preset theme node.

[0093] The interactive poetry system comprises:

[0094] An emotion preset module for determining the user's emotional portrait by searching for related nodes in the multi-dimensional poetry knowledge graph according to the user's interaction history with the system;

[0095] An interactive poetry module for providing users with modification suggestions, completing poems and asking about emotional states to iterate the user's emotional portrait according to the state of the poem and the user's emotional portrait, thereby helping users complete the poem.

[0096] Another embodiment of the present application also discloses an interactive poetry method based on a large language model and a knowledge graph, comprising the steps of constructing a multi-dimensional poetry knowledge graph and an interactive poetry system. Figure 2 As shown in the figure, the method comprises the following steps:

[0097] S1, obtain a poetry data set and remove data in the poetry data set that does not contain appreciation.

[0098] S11, collect poetry data sets composed of ancient poetry authors, appreciation, annotation, comments and other information from the network.

[0099] S12, remove poetry data in the poetry data set that does not contain the appreciation field.

[0100] S13, JSON format the poetry data in the poetry data set obtained in S12 to obtain about 1600 poetry data that actually need to be processed.

[0101] S2, based on a large language model and a text embedding model, extract and map emotion information from poetry appreciation.

[0102] S21, input the poetry appreciation of each poetry data in the poetry data set into the large language model.

[0103] S22, according to the prompt word, the large language model outputs the emotion expressed by the poet in the poem in the format of "this poem expresses the poet's xxx emotion" for subsequent processing.

[0104] S23, input the emotional input obtained in S22 into the acge-text-embedding text embedding model, convert the text representation of the emotion into a numerical vector representation, obtain a first emotional vector, and perform standardization.

[0105] S24, input a plurality of preset 23 emotions (sorrow, pain, desolation, loneliness, indignation, magnanimity, simplicity, optimism, longing, love, missing, melancholy, misery, regret, admiration, sympathy, regret, disgust, reluctance, worry, joy, helplessness, praise) into the acge-text-embedding text embedding model, to obtain a plurality of second emotional vectors.

[0106] S25, respectively, the first emotional vector obtained in S23 and the plurality of second emotional vectors obtained in S24 are calculated by cosine similarity, and the preset emotional text corresponding to the highest cosine similarity is taken as the emotional information of the poem.

[0107] S3, extract the poetic image from the poem by multiple linear regression. The method flow of image extraction is as shown in Figure 3 , including the following steps:

[0108] S31, input the poem content in each piece of poem data into a large language model, according to the prompt word, the large language model outputs the coarse word segmentation result of the poem in the format of "['<word1>', '<word2>',..., '<wordn>']", outputs a list of the same length in Boolean type, and labels whether the output word is a named entity, such as "Yueyang Tower" and "Dongting Lake".

[0109] S32, establish a bi-gram model using the poem data set as a corpus. Specifically, for a classical poem sentence with a length of n , it is considered that the current word is only related to the previous word, that is:

[0110]

[0111] According to Bayes' theorem, we have:

[0112]

[0113] According to the law of large numbers, use to approximate , that is:

[0114]

[0115] wherein, represents the frequency of the phrase or word in the corpus, represents the probability, is the i-th word.

[0116] S33, based on prior knowledge, most five-character poems can use "2 / 2 / 1" or "2 / 1 / 2" segmentation, and most seven-character poems can use "2 / 2 / 2 / 1" or "2 / 2 / 1 / 2" segmentation, in addition to segmentation such as "2 / 3", etc., most of which are caused by named entities.

[0117] For the poem without named entities, it is simply noted as and Two segmentation paradigms. Since the training corpus of large language models is mostly derived from colloquial language, there may be cases where "falling flowers" is divided into "falling" and "flowers". If the output words do not affect the selection of the segmentation paradigm, for example , then the first two words are directly combined as , otherwise, for example , the segmentation mode is taken as:

[0118]

[0119] Among them, represents the conditional probability obtained by the bi-gram model under the segmentation mode, represents the segmentation mode representing "2 / 2 / 1", represents the segmentation mode representing "2 / 1 / 2", is the optimal segmentation mode.

[0120] For the poem with named entities, the part excluding the named entity is traversed in the manner described above for the poem without named entities, and the with the maximum likelihood function value is selected.

[0121] S34, after obtaining the segmentation results of all poems, input the segmentation results into the large language model, and according to the prompt words, the large language model outputs a list of Boolean type, indicating whether each word is a noun excluding named entities, if so, the noun is retained as a poem image candidate word.

[0122] S35, after obtaining the segmentation results of all poems in the poem data set, TF-IDF algorithm is used on all segmentation results to calculate the TF-IDF value, the calculation formula is as follows:

[0123]

[0124] Among them, represents the frequency of image candidate word w in poem s, represents the inverse document frequency of image candidate word w in the entire corpus S, The calculation formula is:

[0125]

[0126] After obtaining the TF-ID values ​​of all image candidate words, normalization is performed.

[0127] S36. Use all image candidate words as nodes and the co-occurrence relationships in the same poem as edges to construct an image candidate word graph , then the score iteration formula for each image candidate word is:

[0128]

[0129] in, is any image candidate word node in the image candidate word graph, is the adjustable damping coefficient, for 、 The cosine similarity between two word vectors, For nodes The in-degree node of For nodes The out-degree node of For nodes TextRank score, for A node in the middle, for A node in the middle, for 、 The cosine similarity between two word vectors, Indicates the Round iteration.

[0130] The score is calculated according to the iterative formula until the scores of all nodes converge.

[0131] S37. After obtaining the TF-IDF value and TextRank score of each image candidate word, it is necessary to assign weights to the TF-IDF value and TextRank score, so that the candidate word with a higher total score after weighted average is used as the image. However, it is difficult to adjust the weights manually, so in this embodiment, multiple linear regression is chosen to learn the weights.

[0132] Obtain the CCPC dataset. The CCPC dataset released by the Natural Language Processing Laboratory of Tsinghua University contains ancient poems and four keywords corresponding to each poem. These four keywords are approximately regarded as images. The image candidate words in each poem are intersected with the four keywords and the intersection is used as a positive sample. Label is 1, otherwise it is a negative sample, label is -1, and the loss function is set as HingeLoss for multivariate linear regression analysis, and the specific calculation method is:

[0133]

[0134] wherein, is a weight vector, is a score vector of a training sample, is a label corresponding to a training sample, denotes transposition.

[0135] The gradient descent method is used for solving, and after the loss converges, the weight at the time of loss convergence is taken as the optimal weight of the TF-IDF value and the TextRank score of the image candidate word, the weighted average is used to calculate the total score of any image candidate word of each poem, and the image candidate word with the highest score is taken as the image.

[0136] S4, using a large language model to extract and map theme information from poem appreciation.

[0137] The poem appreciation of each poem data in the poem data set is input into the large language model, according to the prompt word, the large language model outputs the 9 kinds of theme list (mountain and water, border and military, history and mythology, object and aspiration, farewell and missing, travel and hometown, love and chamber, mourning and country, demotion and exile, other themes) corresponding to the theme of the poem in the prompt word according to the format of “the theme of this poem is: <theme>”, and the theme is taken as the theme information of the poem.

[0138] S5, comprehensive emotion information, poem image and theme information to establish a multi-dimensional poem knowledge graph.

[0139] The knowledge graph nodes and knowledge graph relationships are established, the knowledge graph nodes include poet nodes, poem title nodes, poem sentence nodes, emotion nodes, image nodes, and theme nodes; the knowledge graph relationships include “‘poet’ created ‘poem title’”, “‘poem title’ contains ‘poem sentence’”, “‘poem sentence’ contains ‘image’”, “‘poem sentence’ theme is ‘theme’”, and “‘poem sentence’ emotion is ‘emotion’”. The above knowledge graph nodes and knowledge graph relationships are imported into the Neo4j graph database as a knowledge graph using the py2neo library, so as to obtain a multi-dimensional poem knowledge graph. In this embodiment, the multi-dimensional poem knowledge graph finally obtained contains a total of 26552 nodes and 85477 relationships. As Figure 4 shown in Fig. 1 is a subgraph of the multi-dimensional poem knowledge graph established, which reflects that the ‘Changjiang River at Night’ created by the poet ‘Li Bai’ expresses the emotion of ‘missing’ of the poet, the theme of ‘missing hometown in travel’, and the common image ‘moon’ of the poem sentence ‘sea moon tide together’ and the form of the relationship between these nodes in the knowledge graph.

[0140] The interactive poem writing method flow in this embodiment is as shown in Figure 5 The method includes the following steps:

[0141] S6, establishing a user's emotional portrait based on the user's interaction history.

[0142] According to the user's interaction history with the interactive poem writing system, including the clicked images and poem lines, search for theme nodes and emotional nodes within two hops in the multi-dimensional poem knowledge graph, take the theme nodes and emotional nodes with the highest frequency as the user's preferred theme and current emotional state, and thus establish the user's emotional portrait, and search for images within two hops in the multi-dimensional poem knowledge graph according to the user's preferred theme and current emotional state, and randomly push the images to the user as poem materials.

[0143] S7, interactive auxiliary poem writing creation based on the user's emotional portrait.

[0144] After establishing the user's emotional portrait, the user can start writing poems. The user's poem writing state is divided into three types, namely, an unfinished state of not completing a line, a stage completion state of completing one to three lines, and a completion state of completing all lines, and different interaction modes are set for the three poem writing states to help the user complete the poem writing. As shown in Figure 6 Taking a user's writing process as an example, the user's poem writing state is divided into three types, namely, an unfinished state of not completing a line: “Autumn wind blows leaves” does not fill the first line; a stage completion state of completing one to three lines: completing the first line “Autumn wind blows leaves yellow” and the second line “Cold dew moistens chrysanthemum fragrance”; and a completion state of completing all lines: there is no line to be filled.

[0145] The interaction mode for the unfinished state includes:

[0146] If the user selects the poem materials provided by the system, and the current state of the poem is the unfinished state, fuzzywuzzy library is used to perform fuzzy retrieval on the poem written by the user (the unfinished part is replaced by an underscore), and the image nodes connected to the poem line nodes with the highest similarity are pushed to the user. In addition, if the user is in the unfinished state for a certain period of time, such as 10 minutes in this embodiment, the poem written by the user (the unfinished part is replaced by an underscore) is input into a large language model, and the large language model outputs the completed poem lines and the corresponding reasons in JSON format according to the prompt words, and the user can choose whether to accept.

[0147] The interaction mode for the stage completion state includes:

[0148] If the user creates or selects the image node pushed by the system, and the poem reaches the stage of completion, the user's current poem (unfinished part is replaced by underline) and 23 preset emotion input large language model, the large language model judges which of the 23 preset emotions the current emotional state belongs to according to the prompt word. If it is not consistent with the emotional state in the user's current emotional portrait, ask the user's current emotional state, update the user's emotional portrait, otherwise push the image to the user according to the user's emotional portrait.

[0149] The interaction mode of the completion state includes:

[0150] When the poem reaches the completion state, input the user's poem into the large language model, and the large language model outputs a list of modification suggestions in JSON format according to the prompt word. Each element in the list includes the specific content of the modification suggestion (including the sentence pattern of modifying a certain word to a certain word). Use regular expressions to extract the modification content and match the specific poem, and display the modification suggestions corresponding to the poem to the user in order. The user can choose whether to accept the modification suggestion and complete the poem.

[0151] The above shows and describes the basic principles, main features and advantages of the present application. Those skilled in the art should understand that the present application is not limited to the above embodiments, and the above embodiments and descriptions in the specification are only to illustrate the principles of the present application. Without departing from the spirit and scope of the present application, various changes and improvements can be made to the present application, and these changes and improvements all fall within the scope of the claimed present application. The scope of protection of the present application is defined by the appended claims and their equivalents.

Claims

1. An interactive poem writing system based on a large language model and a knowledge graph, characterized in that, The multi-dimensional poem knowledge graph and the interactive poem writing system are included; The multi-dimensional poem knowledge graph includes: A preprocessing module for removing poem data without appreciation and JSON formatting of poem data; An emotion extraction module for extracting emotion information from poem appreciation and mapping to a preset emotion node; An image extraction module for extracting images in the poem as image nodes of the poem; A theme extraction module for extracting theme information from poem appreciation and mapping to a preset theme node; The interactive poem writing system includes: An emotion preset module for searching theme nodes and emotion nodes within two hops in the multi-dimensional poem knowledge graph according to the interaction history of a user with the interactive poem writing system, taking the theme node and emotion node with the highest frequency as the user's preferred theme and current emotion state, establishing the user's emotion portrait, and searching images within two hops in the multi-dimensional poem knowledge graph according to the user's preferred theme and current emotion state, and randomly pushing the images to the user as poem materials; An interactive poem writing module for providing modification suggestions, completing the poem, and asking about the emotion state to iterate the user's emotion portrait according to the poem state and the user's emotion portrait, thereby helping the user complete the poem, specifically including: Dividing the user's poem state into three categories, namely, an unfinished state of not completing a sentence, a stage completion state of completing one to three sentences, and a completion state of completing all; setting different interaction modes for the three poem states to help the user complete the poem creation; The interaction mode of the unfinished state includes: Using the fuzzywuzzy library to perform fuzzy retrieval on the poem written by the user, pushing the image nodes connected to the poem sentence node with the highest similarity to the user; if the user is in the unfinished state within a time threshold, inputting the poem written by the user into a large language model, and the large language model outputs the completed poem and the corresponding reason, and the user can choose whether to accept it; The interaction mode of the stage completion state includes: Inputting the poem written by the user and the preset emotion into the large language model to determine which type of preset emotion the current emotion state belongs to; if it does not match the emotion state in the user's emotion portrait, ask the user about the current emotion state, update the user's emotion portrait, otherwise, push the image to the user according to the user's emotion portrait; The interaction mode of the completion state includes: Inputting the poem written by the user into a large language model, and the large language model outputs a list of modification suggestions, each element in the list includes the specific content of the modification suggestion, using regular expressions to extract the modification content and match the specific poem, and displaying the poem corresponding to the modification suggestion to the user in order, and the user can choose whether to accept the modification suggestion to complete the poem.

2. An interactive poem writing method based on a large language model and a knowledge graph, characterized in that, The following steps are included: S1, obtaining a poem data set and removing data in the poem data set without appreciation; S2, extracting and mapping emotion information from poem appreciation based on a large language model and a text embedding model; S3, extracting poem images from the poem through multivariate linear regression; S4, extracting and mapping theme information from poem appreciation using a large language model; S5, build a multi-dimensional poem knowledge graph by integrating emotional information, poetic imagery and theme information; S6, build a user's emotional portrait based on the user's interaction history, including the following steps: According to the user's interaction history with the interactive poem writing system, search for theme nodes and emotional nodes within two hops in the multi-dimensional poem knowledge graph, and take the most frequent theme nodes and emotional nodes as the user's preferred theme and current emotional state, thereby establishing the user's emotional portrait, and searching for imagery within two hops in the multi-dimensional poem knowledge graph according to the user's preferred theme and current emotional state, and randomly pushing the imagery to the user as a poem writing material; S7, interactive auxiliary poem writing based on the user's emotional portrait, including the following steps: Divide the user's poem writing state into three categories: unfinished state, stage completion state and completion state; Set different interaction modes for the three poem writing states to help the user complete the poem writing; The interaction mode of the unfinished state includes: Use the fuzzywuzzy library to perform fuzzy search on the poem written by the user, and push the image nodes connected to the poem node with the highest similarity to the user; If the user has been in the unfinished state for a certain time threshold, input the poem written by the user into a large language model, and the large language model outputs the completed poem and the corresponding reason, and the user can choose whether to accept it; The interaction mode of the stage completion state includes: Input the poem written by the user and the preset emotion into a large language model to determine which of the preset emotions the current emotional state belongs to; If it does not match the emotional state in the user's emotional portrait, ask the user about the current emotional state, update the user's emotional portrait, otherwise, push the image to the user according to the user's emotional portrait; The interaction mode of the completion state includes: Input the poem written by the user into a large language model, and the large language model outputs a list of modification suggestions, each element in the list includes the specific content of the modification suggestion, and the modification content is extracted using regular expressions and matched with specific poem lines, and the modification suggestions corresponding to the poem lines are displayed to the user in order, and the user can choose whether to accept the modification suggestions to complete the poem writing.

3. The method of claim 2, wherein the method further comprises: The S1 includes the following steps: S11, collect a poem dataset composed of ancient poems and texts from the network; S12, remove the poem data in the poem dataset that does not contain the appreciation field; S13, JSON format the poem data in the poem dataset obtained in S12.

4. The method according to claim 3, wherein, The S2 includes the following steps: S21, input the poem appreciation of each poem data in the poem dataset into a large language model; S22, the large language model outputs the emotions expressed by the poet in the poem; S23, input the emotion obtained in S22 into a text embedding model to convert the text representation of the emotion into a numerical vector representation to obtain a first emotion vector; S24, input multiple preset emotions into a text embedding model to obtain multiple second emotion vectors; S25, respectively, the first emotion vector obtained in S23 and the plurality of second emotion vectors obtained in S24 are subjected to cosine similarity calculation, and the preset emotion text corresponding to the highest cosine similarity is taken as the emotional information of the poem.

5. The method according to claim 4, wherein, The S3 comprises the following steps: S31, input the poem content in each piece of poem data into a large language model, and the large language model outputs a coarse segmentation result of the poem and simultaneously outputs a list of the same length in a Boolean type, and labels whether the output word is a named entity; S32, the poetry data set is established as a corpus to build a bi-gram model, for the ancient poetry sentence with a length of n It is considered that the current word is only related to the previous word, that is: According to Bayes' theorem, we have: According to the law of large numbers, we can approximate by that is: wherein, denotes the frequency of a phrase or word in a corpus, denotes a probability, is the ith word; S33, for the existence of the named entity, the poem is written as and Two word segmentation paradigm, if the output word does not affect the selection of word segmentation paradigm, then directly merge, otherwise, take the word segmentation mode as: wherein, represents the conditional probability of the word "2 / 2 / 1" in the word segmentation mode, represents the conditional probability of the word "2 / 2 / 1" in the word segmentation mode, represents the conditional probability of the word "2 / 2 / 1" in the word segmentation mode, represents the conditional probability of the word "2 / 2 / 1" in the word segmentation mode, is the optimal word segmentation mode; For the poem sentence in which the named entity exists, the part excluding the named entity is traversed in all the word segmentation manners of the poem sentence in which the named entity does not exist and the one with the maximum likelihood function value is selected ; S34, after obtaining the segmentation result of all poems, input the segmentation result into a large language model, and the large language model outputs a list in a Boolean type, indicating whether each word is a noun other than a named entity, and if so, the noun is retained as a poem image candidate word; S35, using the TF-IDF algorithm on all segmentation results, calculate the TF-IDF value, and the calculation formula is as follows: wherein, represents the frequency of the image candidate word w in the poem s, represents the inverse document frequency of the image candidate word w in the entire corpus S, The calculation formula is: After obtaining the TF-ID value of all image candidate words, perform normalization processing; S36, constructing an image candidate word graph with all image candidate words as nodes and co-occurrence relationship in the same poetic line as edges Then, the score iteration formula of each image candidate word is: for a node in for a node in for , cosine similarity of two word vectors, denotes the round of iteration; According to the score iteration formula, calculate the scores of all nodes until the scores converge; S37, after obtaining the TF-IDF value and the TextRank score of each image candidate word, Obtain the CCPC dataset, which contains ancient poems and four keywords corresponding to each ancient poem, approximate the four keywords as images, take the intersection of the image candidate words in each poem and the four keywords as the positive sample, and the label is 1, and otherwise as the negative sample, the label is -1, and set the loss function as HingeLoss to perform multivariate linear regression analysis, and the specific calculation method is: wherein, is a weight vector, is a score vector of the training sample, is a corresponding label of the training sample, denotes a transpose; After obtaining the optimal weight of the TF-IDF value and the TextRank score of the image candidate word by using the gradient descent method, calculate the total score of any image candidate word of each poem by using weighted average, and take the image candidate word with the highest score as the image.

6. The method of claim 5, wherein the method further comprises: The S4 comprises the following steps: Input the poem appreciation of each piece of poem data in the poem data set into a large language model, and the large language model outputs the corresponding theme in the preset theme list in the prompt word, and takes the theme as the theme information of the poem.

7. The method according to claim 6, wherein, The S5 comprises the following steps: Establish a knowledge graph node and a knowledge graph relationship, wherein the knowledge graph node comprises a poet node, a poem title node, a poem line node, an emotion node, an image node, and a theme node; Use the py2neo library to import the knowledge graph node and the knowledge graph relationship into a Neo4j graph database as a knowledge graph, thereby obtaining a multi-dimensional poem knowledge graph.

Citation Information

Patent Citations

  • Inference type precise intelligent question-answering method based on legal knowledge graph

    CN110377715A

  • Poem recommendation method, poem recommendation device, poem recommendation equipment and storage medium

    CN112632386A