Interactive poem doing system and method based on large language model and knowledge graph

Through an interactive poetry writing system based on large language models and knowledge graphs, combined with multi-dimensional poetry knowledge graphs, it solves the problems of existing poetry generation models that ignore user participation and incomplete knowledge graph information, achieves user emotional portraits and image recommendations, and reduces The difficulty and cost of writing poetry.

CN119337839AActive Publication Date: 2025-01-21SICHUAN UNIV

Patent Information

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

AI Technical Summary

Technical Problem

The existing poetry generation model can only directly generate complete poetry, ignoring user participation, and the existing open source poetry knowledge graphs contain emotions, themes and image information at the same time. Image extraction has problems such as poor word segmentation effect and difficulty in selecting image words. .

Method used

Put forward an interactive poetry system based on large language models and knowledge maps. Through the interaction between users and the system, the user emotional portrait is established, recommended to match the image, assist users to complete the creation, and improve the multi -dimensional poetry of image extraction Knowledge map, including emotion, theme and image information.

Benefits of technology

Through interactive poetry system, the difficulty of making poetry is reduced, helping users express emotions, greatly reduced the cost and difficulty of poetry creation, and established a multi -dimensional poetry knowledge map containing emotional, themes and image information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119337839A_ABST
    Figure CN119337839A_ABST
Patent Text Reader

Abstract

The invention discloses an interactive poem doing system and method based on a large language model and a knowledge graph. The system comprises a preprocessing module, an emotion extraction module, an image extraction module, a theme extraction module, an emotion presetting module and an interactive poem doing module. The method comprises the following steps: S1, removing data which does not contain appreciation in a poem data set; s2, extracting and mapping emotion information; s3, extracting poem images; s4, extracting and mapping theme information; s5, integrating the emotion information, the poem image and the theme information to establish a multi-dimensional poem knowledge graph; s6, establishing an emotion portrait of the user based on the user interaction history; and S7, performing interactive auxiliary poetry creation based on the user emotion portrait. The multi-dimensional poem knowledge graph of the interactive poem making system comprises emotion, theme and image information, the user is assisted to complete creation through interaction, and the poem making difficulty 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, the threshold for poetry creation is relatively high, because the creation process requires a deep understanding of the structure, rhythm, symbolic meaning and language expression of the poem, which is particularly difficult when there is a lack of training and experience. However, with the advancement of artificial intelligence technology, there are many poetry generation models that can help the general public create complete poems. These poetry generation models usually use ancient poetry corpora labeled with emotion and style tags as training data. After the training is completed, the user only needs to input the imagery, emotion or style, and the model can automatically create a complete poem.

[0003] However, the existing poetry generation model can only directly generate a complete poem, ignoring the user's participation, resulting in the user being unable to express their emotions in the process. The existing open source poetry knowledge graph does not contain emotion, theme and image information at the same time, and the extraction of poetry imagery also faces the problem of poor word segmentation and difficulty in selecting image words. Summary of the invention

[0004] In order to solve the problems that the existing poetry generation model can only directly generate complete poems while ignoring user participation and the poetry knowledge graph does 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, aiming to establish a user emotion portrait through the interaction between the user and the system, recommend matching images, and assist the user in completing the creation, and proposes a multi-dimensional poetry knowledge graph for improved image extraction 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; The multi-dimensional poetry knowledge graph includes: Preprocessing module, used to remove poetry data that does not contain appreciation and format poetry data in JSON; Emotion extraction module, used to extract emotional information from poetry appreciation and map it to preset emotional nodes; An image extraction module is used to extract images from poems and use them as image nodes of poems; Theme extraction module, used to extract theme information from poetry appreciation and map it to preset theme nodes; The interactive poetry writing system comprises: The emotion preset module is used to determine the user's emotional profile by searching for relevant nodes in the multi-dimensional poetry knowledge graph based on the user's interaction history with the system; The interactive poetry writing module is used to provide users with modification suggestions, complete the poem, and ask about the emotional state to iterate the user's emotional portrait based on the state of the poem and the user's emotional portrait, thereby helping the user complete the poem.

[0006] The present application also discloses an interactive poetry writing method based on a large language model and a knowledge graph, comprising the following steps: S1, obtain a poetry data set and remove the data that does not contain appreciation in the poetry data set; S2, extracting and mapping emotional information from poetry appreciation based on large speech model and text embedding model; S3, extracting poetic imagery from poetry through multiple linear regression; S4, extracting and mapping thematic information from poetry appreciation using large language models; S5. Establish a multi-dimensional poetry knowledge graph by integrating emotional information, poetic imagery and theme information; S6. Build a user's emotional profile based on the user's interaction history; S7. Interactively assist poetry creation based on user emotional portraits.

[0007] Preferably, the S1 comprises the following steps: S11, a poetry dataset consisting of ancient poetry authors, appreciation, annotations, comments and other information collected from the Internet; S12, removing the poetry data that does not contain the appreciation field in the poetry data set; S13, formatting the poetry data in the poetry data set obtained in S12 into JOSN.

[0008] Preferably, S2 comprises the following steps: S21, inputting the poetry appreciation of each piece of poetry data in the poetry dataset into the large language model; S22, the large language model outputs the emotions expressed by the poet in the poem; S23, inputting the emotion 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 emotion vector, and performing standardization; S24, inputting a plurality of preset 23 emotions (emotion, pain, desolation, loneliness, indignation, heroism, tranquility, optimism, yearning, love, yearning, sadness, depression, grief, admiration, sympathy, regret, disgust, reluctance, worry, joy, helplessness, praise) into the acge-text-embedding text embedding model to obtain a plurality of second emotion vectors; S25. Perform cosine similarity calculation on the first emotion vector obtained in S23 and the multiple second emotion vectors obtained in S24, and take the preset emotion text corresponding to the highest cosine similarity as the emotion information of the poem.

[0009] Preferably, S3 comprises the following steps: S31, input the poem content in each poem data into the large language model, and the large language model outputs the coarse word segmentation result of the poem, and at the same time outputs a list of the same length of the Boolean type, and marks whether the output word is a named entity; S32. Use the poetry dataset as a corpus to build a bi-gram model. For an ancient poem with a length of n , it is considered that the current word is only related to the previous word, that is:

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

[0011] According to the law of large numbers, use To approximate ,Right now:

[0012] in, Indicates the frequency of a phrase or word in the corpus. represents the probability, is the i-th word; S33. For verses without named entities, simply write and There are two segmentation paradigms. If the output words do not affect the choice of segmentation paradigm, they are directly merged. Otherwise, the segmentation method is:

[0013] in, Indicated in In the word segmentation mode, the conditional probability approximated by the bi-gram model is: It represents the word segmentation method of "2 / 2 / 1". It represents the word segmentation method of "2 / 1 / 2". It is the optimal word segmentation method; For the verses with named entities, the part other than the named entities is traversed through all the word segmentation methods in the same way as the verses without named entities and the one with the largest likelihood function value is selected. ; S34, after obtaining the word segmentation results of all poems, the word segmentation results are input into the large language model, and the large language model outputs a Boolean list indicating whether each word is a noun other than a named entity, and if so, the noun is retained as a candidate word for the poem image; S35. Use the TF-IDF algorithm on all word segmentation results to calculate the TF-IDF value. The calculation formula is as follows:

[0014] in, 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:

[0015] After obtaining the TF-ID values ​​of all image candidate words, normalize them; 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:

[0016] for In the first node, for In the first node, for , The cosine similarity between two word vectors, Indicates Round iteration; Calculate according to the score iteration formula until the scores of all nodes converge; S37. After obtaining the TF-IDF value and TextRank score of each image candidate word, Get the CCPC dataset, which contains ancient poems and four keywords corresponding to each poem. The four keywords are approximately regarded as images. The image candidate words in each poem are intersected with the four keywords, and the intersection is taken as a positive sample. is 1, otherwise it is a negative sample, label is -1, and the loss function is set to HingeLoss to perform multiple linear regression analysis. The specific calculation method is:

[0017] in, is the weight vector, is the score vector of the training sample, is the label corresponding to the training sample, represents transpose; After using the gradient descent method to obtain the optimal weights of the TF-IDF value and TextRank score of the image candidate words, the total score of any image candidate word in each poem is calculated using weighted average, and the image candidate word with the highest score is taken as the image.

[0018] Preferably, S4 comprises the following steps: The poetry appreciation of each poem data in the poetry dataset is input into the big language model. According to the prompt word, the big speech model outputs the corresponding theme of the poem in the 9 theme lists preset in the prompt word (landscape and countryside, frontier military, historical mythology, objects and aspirations, farewell and homesickness, love and boudoir resentment, mourning and worrying about the country, demotion and exile, and other themes) in the format of "the theme of this poem is: <theme>", and uses this theme as the theme information of the poem.

[0019] Preferably, S5 comprises the following steps: Establishing knowledge graph nodes and knowledge graph relationships, wherein the knowledge graph nodes include poet nodes, poem title nodes, verse nodes, emotion nodes, image nodes, and theme nodes; The py2neo library is used to import the knowledge graph nodes and knowledge graph relationships into the Neo4j graph database as a knowledge graph, thereby obtaining a multi-dimensional poetry knowledge graph.

[0020] Preferably, S6 comprises the following steps: According to the interaction history between the user and the interactive poetry writing system, the multi-dimensional poetry knowledge graph is searched for topic nodes and emotional nodes within two hops, and the most frequent topic nodes and emotional nodes are used as the user's preferred topics and current emotional states, so as to establish the user's emotional portrait. Based on the user's preferred topics and current emotional states, the multi-dimensional poetry knowledge graph is searched for images within two hops, and randomly pushed to the user as poetry writing materials.

[0021] Preferably, the S8 comprises the following steps: The user's poetry writing status is divided into three types: the unfinished state with one sentence not completed, the phased completion state with one to three sentences completed, and the completed state with all sentences completed; Different interaction methods are set for the three poetry writing states to help users complete poetry creation.

[0022] Preferably, the interaction mode of the unfinished state includes: Use the fuzzywuzzy library to perform fuzzy search on the user's poems, and push the image nodes connected to the retrieved poem nodes with the highest similarity to the user; if the user is in an unfinished state within the time threshold, the user's poem is input into the 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 modes of the phased completion status include: Input the user's current poem and preset emotions into the big 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 current emotional profile, ask the user about the current emotional state and update the user's emotional profile; otherwise, push images to the user based on the user's emotional profile; The interaction methods of the completion status include: The poem written by the user is input into the big language model, and the big language model outputs a list of modification suggestions. Each element in the list includes the specific content of the modification suggestion. Regular expressions are used to extract the modification content and match specific verses. The modification suggestions corresponding to the verses are displayed to the user in order. The user can choose whether to accept the modification suggestions and complete the poem.

[0023] Beneficial effects of the present invention: (1) The interactive poetry writing system proposed in the invention creates poetry in the form of collage poetry, which reduces the difficulty of poetry writing. In the interactive process, it uses a large language model to provide modification suggestions and complete verses to assist users in completing creation and expressing emotions, which greatly reduces the cost and difficulty of poetry creation.

[0024] (2) The interactive poetry writing system proposed in the present invention establishes a user emotional profile through interaction between the user and the system, recommends matching images, and assists the user in completing creation and expressing emotions.

[0025] (3) The present invention proposes a multi-dimensional poetry knowledge graph for improving image extraction, and ultimately establishes a multi-dimensional poetry knowledge graph containing 26,552 nodes and 85,477 relationships. The multi-dimensional poetry knowledge graph also contains emotion, theme and image information. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 A schematic diagram of the composition of an interactive poetry writing system based on a large language model and a knowledge graph according to an embodiment of the present invention; Figure 2 A flowchart for constructing a multi-dimensional poetry knowledge graph according to an embodiment of the present invention; Figure 3 is a flow chart of an image extraction method according to an embodiment of the present invention; Figure 4 A subgraph in the multi-dimensional poetry knowledge graph of an embodiment of the present invention; Figure 5 A flow chart of an interactive poetry writing method according to an embodiment of the present invention; Figure 6 Schematic diagram of three poetry writing states according to an embodiment of the present invention. DETAILED DESCRIPTION

[0027] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below with reference to the accompanying drawings and examples.

[0028] An embodiment of the present application discloses an interactive poetry writing system based on a large language model and a knowledge graph, such as Figure 1 As shown, it includes a multi-dimensional poetry knowledge graph and an interactive poetry writing system.

[0029] The multi-dimensional poetry knowledge graph includes: Preprocessing module, used to remove poetry data that does not contain appreciation and format poetry data in JSON; Emotion extraction module, used to extract emotional information from poetry appreciation and map it to preset emotional nodes; An image extraction module is used to extract images from poems and use them as image nodes of poems; The theme extraction module is used to extract theme information from poetry appreciation and map it to preset theme nodes.

[0030] The interactive poetry writing system includes: The emotion preset module is used to determine the user's emotional profile by searching for relevant nodes in the multi-dimensional poetry knowledge graph based on the user's interaction history with the system; The interactive poetry writing module is used to provide users with modification suggestions, complete the poem, and ask about the emotional state to iterate the user's emotional portrait based on the state of the poem and the user's emotional portrait, thereby helping the user complete the poem.

[0031] Another embodiment of the present application also discloses an interactive poetry writing method based on a large language model and a knowledge graph, the steps of which include constructing a multi-dimensional poetry knowledge graph and interactive poetry writing. The method flow of constructing a multi-dimensional poetry knowledge graph is as follows: Figure 2 As shown, the following steps are included: S1. Obtain a poetry dataset and remove data that does not contain appreciation in the poetry dataset.

[0032] S11. A poetry dataset consisting of information such as authors, appreciation, annotations, and comments of ancient poems collected from the Internet.

[0033] S12. Remove poetry data that does not contain an appreciation field from the poetry data set.

[0034] S13. Format the poetry data in the poetry data set obtained in S12 into JOSN format to obtain about 1,600 pieces of poetry data that actually need to be processed.

[0035] S2. Extract and map emotional information from poetry appreciation based on a large speech model and text embedding model.

[0036] S21. Input the poetry appreciation of each poetry data in the poetry dataset into the big language model.

[0037] S22. According to the prompt word, the large language model outputs the emotions expressed by the poet in the poem in the format of "this poem expresses the emotions of the poet xxx" to facilitate subsequent processing.

[0038] S23. Input the emotion obtained in S22 into the acge-text-embedding text embedding model, convert the text representation of the emotion into a numerical vector representation, obtain the first emotion vector, and standardize it.

[0039] S24. Input a variety of preset 23 emotions (emotion, pain, desolation, loneliness, indignation, heroism, tranquility, optimism, yearning, love, longing, melancholy, depression, grief, admiration, sympathy, regret, disgust, reluctance, worry, joy, helplessness, and praise) into the acge-text-embedding text embedding model to obtain multiple second emotion vectors.

[0040] S25. Perform cosine similarity calculation on the first emotion vector obtained in S23 and the multiple second emotion vectors obtained in S24, and take the preset emotion text corresponding to the highest cosine similarity as the emotion information of the poem.

[0041] S3. Extract poetic images from poems through multivariate linear regression. The image extraction method flow is as follows: Figure 3 As shown, the following steps are included: S31. Input the poem content in each poem data into the large language model. According to the prompt word, the large language model outputs the rough word segmentation result of the poem in the format of "['<Word 1>','<Word 2>',...,'<Word n>']", and outputs a list of the same length of Boolean type at the same time, and marks whether the output word is a named entity, such as "Yueyang Tower", "Dongting Lake", etc.

[0042] S32. Use the poetry dataset as a corpus to build a bi-gram model. Specifically, for an ancient poem with a length of n , it is considered that the current word is only related to the previous word, that is:

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

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

[0045] where represents the frequency of a phrase or word appearing in the corpus, represents the probability, is the i-th word.

[0046] S33. Based on prior knowledge, it is known that most five-character poems can adopt the word segmentation methods of "2 / 2 / 1" or "2 / 1 / 2", and most seven-character poems can adopt the word segmentation methods of "2 / 2 / 2 / 1" or "2 / 2 / 1 / 2". In addition, there are also word segmentation methods such as "2 / 3", etc., which are mostly caused by named entities.

[0047] For the verses without named entities, they are simply recorded as and two word segmentation paradigms. Since most of the training corpus of the large language model comes from vernacular Chinese, there is a situation where "falling flowers" is segmented into "fall" and "flowers". If the words output in this situation do not affect the choice of word segmentation paradigm, for example , then directly merge the first two words into , otherwise, for example , then take the word segmentation method as:

[0048] where represents the conditional probability approximately obtained by the bi-gram model under the word segmentation method, represents the word segmentation method representing "2 / 2 / 1", represents the word segmentation method representing "2 / 1 / 2", is the optimal word segmentation method.

[0049] For the verses with named entities, traverse all word segmentation methods for the part except the named entity in the same way as the verses without named entities above and select the one that maximizes the likelihood function value of .

[0050] S34. After obtaining the word segmentation results of all poems, input the word segmentation results into the large language model. According to the prompt words, the large language model outputs a list of boolean types, indicating whether each word is a noun except for named entities. If so, retain the noun as a candidate for poem imagery.

[0051] S35. After obtaining the word segmentation results of all poems in the poetry dataset, the TF-IDF algorithm is used on all the word segmentation results to calculate the TF-IDF value. The calculation formula is as follows:

[0052] in, 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:

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

[0054] 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:

[0055] 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 Node The in-degree node of For Node The out-degree node of For Node The TextRank score, for In the first node, for In the first node, for , The cosine similarity between two word vectors, Indicates Round iteration. The score iteration formula is used to calculate until the scores of all nodes converge.

[0056] S37. After obtaining the TF-IDF value and TextRank score of each image candidate word, weights need to be assigned 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. Therefore, in this embodiment, multiple linear regression is chosen to learn the weights.

[0057] 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 taken as a positive sample. Label is 1, otherwise it is a negative sample, label is -1, and the loss function is set to HingeLoss to perform multiple linear regression analysis. The specific calculation method is:

[0058] in, is the weight vector, is the score vector of the training sample, is the label corresponding to the training sample, Indicates transpose.

[0059] The gradient descent method is used to solve the problem. After the loss converges, the weight at the time of loss convergence is used as the optimal weight of the TF-IDF value and TextRank score of the image candidate word. The total score of any image candidate word in each poem is calculated using weighted average, and the image candidate word with the highest score is taken as the image.

[0060] S4. Extract and map thematic information from poetry appreciation using a large language model.

[0061] The poetry appreciation of each poem data in the poetry dataset is input into the big language model. According to the prompt word, the big speech model outputs the corresponding theme of the poem in the 9 theme lists preset in the prompt word (landscape and countryside, frontier military, historical mythology, objects and aspirations, farewell and homesickness, love and boudoir resentment, mourning and worrying about the country, demotion and exile, and other themes) in the format of "the theme of this poem is: <theme>", and uses this theme as the theme information of the poem.

[0062] S5. Integrate emotional information, poetic imagery and theme information to establish a multi-dimensional poetry knowledge graph.

[0063] Establish knowledge graph nodes and knowledge graph relationships. The knowledge graph nodes include poet nodes, poem title nodes, verse nodes, emotion nodes, image nodes, and theme nodes. The knowledge graph relationships include "'poet' created 'poem title'", "'poem title' contains 'verse'", "'verse' contains 'image'", "the theme of 'verse' is 'theme'", and "the emotion of 'verse' is 'emotion'". Use the py2neo library to import the above knowledge graph nodes and knowledge graph relationships into the Neo4j graph database as a knowledge graph, thereby obtaining a multi-dimensional poetry knowledge graph. The multi-dimensional poetry knowledge graph finally obtained in this embodiment contains a total of 26,552 nodes and 85,477 relationships. As Figure 4 The figure shows a subgraph of the established multi-dimensional poetry knowledge graph, which reflects that the poem "Quiet Night Thoughts" written by the poet "Li Bai" expresses the poet's emotion of "missing", the theme of "homesickness during travel", and the common image of the line "The bright moon on the sea rises with the tide". The nodes and the relationship between them are displayed in the knowledge graph.

[0064] The interactive poetry writing method process in this embodiment is as follows Figure 5 As shown, the following steps are included: S6. Build a user's emotional profile based on the user's interaction history.

[0065] Based on the user's interaction history with the interactive poetry writing system, including the images and verses clicked, the multidimensional poetry knowledge graph is searched for topic nodes and emotional nodes within two hops. The most frequent topic nodes and emotional nodes are used as the user's preferred topics and current emotional states, thereby establishing the user's emotional portrait. Based on the user's preferred topics and current emotional states, the multidimensional poetry knowledge graph is searched for images within two hops, and randomly pushed to the user as poetry writing materials.

[0066] S7. Interactively assist poetry creation based on user emotional portraits.

[0067] After establishing the user's emotional portrait, the user can start writing poetry. The user's poetry writing status is divided into three types: the unfinished state with one sentence unfinished, the phased completion state with one to three sentences completed, and the completed state with all completed. Different interaction methods are set for these three poetry writing states to help users complete poetry creation. Figure 6 As shown, taking a user's creative process as an example, the user's poetry writing status is divided into three types, namely, an unfinished state with an unfinished sentence: "Autumn wind blows the leaves" has not filled in the first sentence; a phased completion state with one to three sentences completed: the first sentence "Autumn wind blows the leaves yellow" and the second sentence "Cold dew moistens the chrysanthemums" are completed; and a completed state with all sentences completed: there are no unfilled sentences.

[0068] The interaction modes of the unfinished state include: If the user selects the poetry material provided by the system, and the current state of the poem is unfinished, the fuzzywuzzy library is used to perform fuzzy search on the poem written by the user (the unfinished part is replaced by an underscore), and the image node connected to the poem node with the highest similarity is pushed to the user. In addition, if the user is in an 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 the large language model, and the large language model outputs the completed poem and the corresponding reason in JSON format according to the prompt word, and the user can choose whether to accept it.

[0069] The interactive modes of the phased completion status include: If the user is creating his own poem or selecting an image node pushed by the system, and the poem reaches a staged completion state, the poem currently written by the user (the unfinished part is replaced by an underline) and 23 preset emotions are input into the large language model. The large language model determines which of the 23 preset emotions the current emotional state belongs to based on the prompt words. If it does not match the emotional state in the user's current emotional portrait, the user's current emotional state is asked and the user's emotional portrait is updated. Otherwise, the image is pushed to the user based on the user's emotional portrait.

[0070] The interaction modes for the completion state include: When the poem reaches the completed state, the poem written by the user is input into the large language model. The large language model outputs a list of modification suggestions according to the prompt word in JSON format. Each element in the list includes the specific content of the modification suggestion (including the sentence pattern of changing a certain word to a certain word). Regular expressions are used to extract the modification content and match specific verses. The modification suggestions corresponding to the verses are displayed to the user in order. The user can choose whether to accept the modification suggestions and complete the poem.

[0071] The above shows and describes the basic principles, main features and advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. An interactive poetry writing system based on a large language model and knowledge graph, characterized in that: Includes a multi-dimensional poetry knowledge graph and an interactive poetry writing system; The multi-dimensional poetry knowledge graph includes: Preprocessing module, used to remove poetry data that does not contain appreciation and format poetry data in JSON; Emotion extraction module, used to extract emotional information from poetry appreciation and map it to preset emotional nodes; An image extraction module is used to extract images from poems and use them as image nodes of poems; Theme extraction module, used to extract theme information from poetry appreciation and map it to preset theme nodes; The interactive poetry writing system comprises: The emotion preset module is used to determine the user's emotional profile by searching for relevant nodes in the multi-dimensional poetry knowledge graph based on the user's interaction history with the system; The interactive poetry writing module is used to provide users with modification suggestions, complete the poem, and ask about the emotional state to iterate the user's emotional portrait based on the state of the poem and the user's emotional portrait, thereby helping the user complete the poem.

2. An interactive poetry writing method based on a large language model and knowledge graph, characterized in that: The following steps are involved: S1, obtain a poetry data set and remove the data that does not contain appreciation in the poetry data set; S2, extracting and mapping emotional information from poetry appreciation based on large speech model and text embedding model; S3, extracting poetic imagery from poetry through multiple linear regression; S4, extracting and mapping thematic information from poetry appreciation using large language models; S5. Establish a multi-dimensional poetry knowledge graph by integrating emotional information, poetic imagery and theme information; S6. Build a user's emotional profile based on the user's interaction history; S7. Interactively assist poetry creation based on user emotional portraits.

3. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 2 is characterized in that: The S1 comprises the following steps: S11, a poetry dataset consisting of ancient poems collected from the Internet; S12, removing the poetry data that does not contain the appreciation field in the poetry data set; S13, formatting the poetry data in the poetry data set obtained in S12 into JOSN.

4. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 3 is characterized in that: The S2 comprises the following steps: S21, inputting the poetry appreciation of each piece of poetry data in the poetry dataset into the large language model; S22, the large language model outputs the emotions expressed by the poet in the poem; S23, embedding the emotion input text obtained in S22 into the model, converting the text representation of the emotion into a numerical vector representation, and obtaining a first emotion vector; S24, embedding a plurality of preset emotions into the text into the model to obtain a plurality of second emotion vectors; S25. Perform cosine similarity calculation on the first emotion vector obtained in S23 and the multiple second emotion vectors obtained in S24, and take the preset emotion text corresponding to the highest cosine similarity as the emotion information of the poem.

5. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 4 is characterized in that: The S3 comprises the following steps: S31, input the poem content in each poem data into the large language model, and the large language model outputs the coarse word segmentation result of the poem, and at the same time outputs a list of the same length of the Boolean type, and marks whether the output word is a named entity; S32. Use the poetry dataset as a corpus to build a bi-gram model. For an ancient poem 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, use To approximate ,Right now: in, Indicates the frequency of a phrase or word in the corpus. represents the probability, is the i-th word; S33. For verses without named entities, simply write and There are two segmentation paradigms. If the output words do not affect the choice of segmentation paradigm, they are directly merged. Otherwise, the segmentation method is: in, Indicated in In the word segmentation mode, the conditional probability approximated by the bi-gram model is: It represents the word segmentation method of "2 / 2 / 1". It represents the word segmentation method of "2 / 1 / 2". It is the optimal word segmentation method; For the verses with named entities, the part other than the named entities is traversed through all the word segmentation methods in the same way as the verses without named entities and the one with the largest likelihood function value is selected. ; S34, after obtaining the word segmentation results of all poems, the word segmentation results are input into the large language model, and the large language model outputs a Boolean list indicating whether each word is a noun other than a named entity, and if so, the noun is retained as a candidate word for the poem image; S35. Use the TF-IDF algorithm on all word segmentation results to calculate the TF-IDF value. The calculation formula is as follows: in, 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 values ​​of all image candidate words, normalize them; 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: for In the first node, for In the first node, for , The cosine similarity between two word vectors, Indicates Round iteration; Calculate according to the score iteration formula until the scores of all nodes converge; S37. After obtaining the TF-IDF value and TextRank score of each image candidate word, Get the CCPC dataset, which contains ancient poems and four keywords corresponding to each poem. The four keywords are approximately regarded as images. The image candidate words in each poem are intersected with the four keywords, and the intersection is taken as a positive sample. is 1, otherwise it is a negative sample, label is -1, and the loss function is set to HingeLoss to perform multiple linear regression analysis. The specific calculation method is: in, is the weight vector, is the score vector of the training sample, is the label corresponding to the training sample, represents transpose; After using the gradient descent method to obtain the optimal weights of the TF-IDF value and TextRank score of the image candidate words, the total score of any image candidate word in each poem is calculated using weighted average, and the image candidate word with the highest score is taken as the image.

6. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 5, characterized in that: The S4 comprises the following steps: The poetry appreciation of each piece of poetry data in the poetry data set is input into the big language model, and the big speech model outputs the corresponding theme of the poem in the preset theme list in the prompt word, and uses the theme as the theme information of the poem.

7. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 6 is characterized in that: The S5 comprises the following steps: Establishing knowledge graph nodes and knowledge graph relationships, wherein the knowledge graph nodes include poet nodes, poem title nodes, verse nodes, emotion nodes, image nodes, and theme nodes; The py2neo library is used to import the knowledge graph nodes and knowledge graph relationships into the Neo4j graph database as a knowledge graph, thereby obtaining a multi-dimensional poetry knowledge graph.

8. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 7 is characterized in that: The S6 comprises the following steps: According to the interaction history between the user and the interactive poetry writing system, the multi-dimensional poetry knowledge graph is searched for topic nodes and emotional nodes within two hops, and the most frequent topic nodes and emotional nodes are used as the user's preferred topics and current emotional states, so as to establish the user's emotional portrait. Based on the user's preferred topics and current emotional states, the multi-dimensional poetry knowledge graph is searched for images within two hops, and randomly pushed to the user as poetry writing materials.

9. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 7, characterized in that: The S8 comprises the following steps: The user's poetry writing status is divided into three types: the unfinished state with one sentence not completed, the phased completion state with one to three sentences completed, and the completed state with all sentences completed; Different interaction methods are set for the three poetry writing states to help users complete poetry creation.

10. The interactive poetry writing method based on a large language model and a knowledge graph according to claim 9, characterized in that: The interaction methods of the unfinished state include: Use the fuzzywuzzy library to perform fuzzy search on the user's poems, and push the image nodes connected to the retrieved poem nodes with the highest similarity to the user; if the user is in an unfinished state within the time threshold, the user's poem is input into the 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 modes of the phased completion status include: Input the user's current poem and preset emotions into the big 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 current emotional profile, ask the user about the current emotional state and update the user's emotional profile; otherwise, push images to the user based on the user's emotional profile; The interaction methods of the completion status include: The poem written by the user is input into the big language model, and the big language model outputs a list of modification suggestions. Each element in the list includes the specific content of the modification suggestion. Regular expressions are used to extract the modification content and match specific verses. The modification suggestions corresponding to the verses are displayed to the user in order. The user can choose whether to accept the modification suggestions and complete the poem.

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

  • Knowledge graph construction method for Tang poetry knowledge and Tang poetry knowledge question-answering system

    CN112989068A

  • Graph feature extractor training method, poem generation method, equipment and storage medium

    CN115599887A

  • Information recommendation method and device

    CN118797146A

Cited By

  • Intelligent construction method for multi-level emotion differentiation of Chinese ocean poems

    CN121212110A