A method and related device for generating poetry
By using fine-grained attribute information and a preset language model in the poetry generation model, the problem of unrefined attribute control of poetry generation in the existing technology is solved, and higher attribute controllability is achieved.
Patent Information
- Application Number
- CN202011554856.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-24
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2040-12-24
AI Technical Summary
Existing poetry generation methods, such as the planning-implementation method and the GPT model, are difficult to perform fine-grained attribute control when generating poetry, resulting in low attribute controllability.
By pre-training a preset language model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, the fine-grained attribute information of the poetry text to be generated is determined, and the poetry generation model is used to generate the target poetry text to achieve fine-grained attribute control. .
It improves the attribute controllability when generating poetry, makes the attribute control more detailed, and improves the accuracy of attribute control when generating poetry.
Smart Images

Figure CN112651235B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method for generating poetry and related devices. Background Art
[0002] With the rapid development of machine learning technology, especially the update of language models, the effect and ability of text generation have been greatly improved. The core of text generation is to generate text with controllable attributes, consistent logic and fluent semantics; poetry texts have gradually become a testing ground and golden indicator for testing the attribute control, logic control and semantic control of text generation models due to their fixed format, strong logic and good fun.
[0003] At present, the planning-realization method is used to generate poems. Specifically, the planning model is used to obtain the theme of the poem to be generated, and then the pre-trained language model is used to generate the poem according to the plan. Alternatively, the generative pre-training language (English: Generative Pre-Training, abbreviated: GPT) model is used to generate words. Specifically, the name and title of the tune to be generated are input into the pre-trained GPT model to generate words.
[0004] After research, the inventor found that the planning-implementation method has a general effect in generating poems, and the model is relatively complex, with high labor costs; the GPT model cannot perform relevant attribute control when generating words. Although the above two methods can generate poems, they cannot perform fine-grained attribute control when generating poems, resulting in low attribute controllability and lack of detail when generating poems. Summary of the invention
[0005] In view of this, the present application provides a method and related device for generating poetry, which performs fine-grained attribute control when generating poetry, making the attribute control more detailed, thereby improving the controllability of the attributes when generating poetry.
[0006] In a first aspect, an embodiment of the present application provides a method for generating poetry, the method comprising:
[0007] Determine fine-grained attribute information of the poem text to be generated;
[0008] Based on the fine-grained attribute information of the to-be-generated poetry text and the poetry generation model, a target poetry text is obtained;
[0009] The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and a preset language model pre-trained for the poetry text to be trained.
[0010] Optionally, the training steps of the poetry generation model include:
[0011] Obtain the poem text to be trained;
[0012] Analyzing the fine-grained attribute information of the poem text to be trained;
[0013] Based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, the preset language model is trained to obtain the poetry generation model.
[0014] Optionally, the step of training the preset language model to obtain the poetry generation model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained includes:
[0015] Inputting the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text;
[0016] Adjusting the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and the preset poetry text loss function;
[0017] The trained preset language model is used as the poetry generation model.
[0018] Optionally, the preset language model is specifically a generative pre-trained language GPT model.
[0019] Optionally, the fine-grained attribute information includes at least two of type information, theme information, keyword information, rhyme information, style information and sentiment information.
[0020] Optionally, also include:
[0021] Obtaining extended information of the fine-grained attribute information of the poem text to be generated;
[0022] Correspondingly, the method of obtaining a target poetry text based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model includes:
[0023] Selecting input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information;
[0024] The input control information is input into the poetry generation model to obtain the target poetry text.
[0025] Optionally, the step of obtaining extended information of the fine-grained attribute information of the poem text to be generated includes:
[0026] According to the fine-grained attribute information of the poem text to be generated, matching is performed in a poem attribute knowledge base; wherein the poem attribute knowledge base is obtained based on the fine-grained attribute information of historical poem texts mined in advance;
[0027] The matching result of the fine-grained attribute information different from the poem text to be generated is used as the extended information.
[0028] In a second aspect, an embodiment of the present application provides a device for generating poetry, the device comprising:
[0029] A determination unit, used to determine fine-grained attribute information of the poem text to be generated;
[0030] A first obtaining unit, configured to obtain a target poetry text based on the fine-grained attribute information of the poetry text to be generated and a poetry generation model;
[0031] The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and a preset language model pre-trained for the poetry text to be trained.
[0032] Optionally, the device further comprises:
[0033] An acquisition unit, used for acquiring the poem text to be trained;
[0034] An analysis unit, used for analyzing the fine-grained attribute information of the poem text to be trained;
[0035] A training unit is used to train the preset language model to obtain the poetry generation model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained.
[0036] Optionally, the training unit includes:
[0037] A first obtaining subunit is used to input the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text;
[0038] An adjustment subunit, configured to adjust the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and a preset poetry text loss function;
[0039] The first is a subunit, which is used to use the trained preset language model as the poetry generation model.
[0040] Optionally, the preset language model is specifically a generative pre-trained language GPT model.
[0041] Optionally, the fine-grained attribute information includes at least two of type information, theme information, keyword information, rhyme information, style information and sentiment information.
[0042] Optionally, the device further comprises:
[0043] A second obtaining unit is used to obtain extended information of the fine-grained attribute information of the poem text to be generated;
[0044] Correspondingly, the first obtaining unit includes:
[0045] A selection subunit, used to select input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information;
[0046] The second acquisition subunit is used to input the input control information into the poetry generation model to obtain the target poetry text.
[0047] Optionally, the second obtaining unit includes:
[0048] A matching subunit, used for matching the fine-grained attribute information of the poem text to be generated in a poem attribute knowledge base; wherein the poem attribute knowledge base is obtained based on the fine-grained attribute information of the historical poem text mined in advance;
[0049] The second subunit is used to use the matching result of the fine-grained attribute information different from the poem text to be generated as the extended information.
[0050] In a third aspect, an embodiment of the present application provides a device for generating poetry, the device comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations:
[0051] A determination unit, used to determine fine-grained attribute information of the poem text to be generated;
[0052] A first obtaining unit, configured to obtain a target poetry text based on the fine-grained attribute information of the poetry text to be generated and a poetry generation model;
[0053] The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and a preset language model pre-trained for the poetry text to be trained.
[0054] In a fourth aspect, an embodiment of the present application provides a machine-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the device to perform a method for generating poetry as described in any one of the first aspects.
[0055] Compared with the prior art, this application has at least the following advantages:
[0056] By adopting the technical solution of the embodiment of the present application, based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, a preset language model is pre-trained to obtain a poetry generation model; the fine-grained attribute information of the poetry text to be generated is determined; based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model, the target poetry text is obtained. It can be seen that by determining the fine-grained attribute information of the poetry itself and adopting a relatively simple model, fine-grained attribute control can be performed when generating poetry, making the attribute control more detailed, thereby improving the attribute controllability when generating poetry. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0058] Figure 1 A schematic diagram of a system framework involved in an application scenario in an embodiment of the present application;
[0059] Figure 2 A flowchart of a method for training a poetry generation model provided in an embodiment of the present application;
[0060] Figure 3 A schematic diagram of a poetry generation model training framework provided in an embodiment of the present application;
[0061] Figure 4 A flowchart of a method for generating poetry provided in an embodiment of the present application;
[0062] Figure 5 A schematic diagram of the structure of a device for generating poetry provided in an embodiment of the present application;
[0063] Figure 6 A schematic diagram of the structure of a device for generating poetry provided in an embodiment of the present application;
[0064] Figure 7 A schematic diagram of the structure of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0065] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0066] At present, the planning-implementation method is used to generate poems, that is, the planning model is first used to obtain the theme of the poem to be generated, and then a pre-trained language model is used to generate the poem according to the plan. Alternatively, the GPT model is used to generate words, that is, the name of the tune and the title of the word to be generated are input into the pre-trained GPT model to generate words. After research, the inventors found that the effect of generating poems by the planning-implementation method is general, the model is relatively complex, and the labor cost is high; the GPT model generates words and cannot perform relevant attribute control. Although the above two methods can generate poems, they cannot perform fine-grained attribute control when generating poems, resulting in low attribute controllability and lack of detail when generating poems.
[0067] In order to solve this problem, in an embodiment of the present application, based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, a preset language model is pre-trained to obtain a poetry generation model; the fine-grained attribute information of the poetry text to be generated is determined; based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model, the target poetry text is obtained. It can be seen that by determining the fine-grained attribute information of the poetry itself and using a relatively simple model, fine-grained attribute control can be performed when generating poetry, making the attribute control more detailed, thereby improving the attribute controllability when generating poetry.
[0068] For example, one of the scenarios of the embodiment of the present application may be applied to Figure 1 In the scenario shown, the scenario includes a user terminal 101 and a processor 102. The user inputs fine-grained attribute information of the poem text to be generated through the user terminal 101 and sends it to the processor 102. The processor 102 obtains the target poem text using the specific implementation method of poem generation provided in the embodiment of the present application and sends it to the user terminal 101 so that the user terminal 101 displays the target poem text to the user.
[0069] It can be understood that in the above application scenario, although the action description of the implementation mode of the present application is executed by the processor 102, the present application is not limited in terms of the execution subject, as long as the actions disclosed in the implementation mode of the present application are executed.
[0070] It can be understood that the above scenario is only an example scenario provided by the embodiment of the present application, and the embodiment of the present application is not limited to this scenario.
[0071] The specific implementation of the poetry generation method and related devices in the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0072] Exemplary Methods
[0073] Since the premise of realizing poetry generation in this application is to train a poetry generation model, the following is combined with the attached Figure 2 , an example is used to describe in detail the specific implementation method of the poetry generation model training method in the embodiment of the present application.
[0074] See also Figure 2 , shows a flow chart of a method for training a poetry generation model in an embodiment of the present application. In this embodiment, the method may include the following steps:
[0075] Step 201: Obtain the poem text to be trained.
[0076] In the embodiment of the present application, the prerequisite for training a poetry generation model is to obtain training data for the model, and to obtain the training data for the model, it is first necessary to collect a large amount of existing poetry texts as poetry texts to be trained.
[0077] Step 202: Analyze the fine-grained attribute information of the poem text to be trained.
[0078] In an embodiment of the present application, after the poem text to be trained is obtained in step 201, since the planning-implementation method in the prior art generates poems and the GPT model generates words, it is not possible to perform fine-grained attribute control when generating poems, resulting in low attribute controllability and lack of detail when generating poems. Therefore, in addition to the poem text to be trained, the training data of the model also needs to analyze the poem text to be trained to obtain fine-grained attribute information of the poem text to be trained, and use the fine-grained attribute information of the poem text to be trained as the training data of the model, so that in the subsequent process of training to obtain the poem generation model, fine-grained attribute control can be performed when generating poems, making the attribute control more detailed, thereby improving the attribute controllability when generating poems.
[0079] In the embodiment of the present application, the fine-grained attributes of the poem itself generally refer to the type, theme, keyword, rhyme, style, emotion, etc. of the poem. Therefore, in an optional implementation of the embodiment of the present application, in order to better perform fine-grained attribute control when generating poems, the fine-grained attribute information includes at least two of type information, theme information, keyword information, rhyme information, style information, and emotion information.
[0080] Among them, the type information of the poetry text to be trained can be obtained through type analysis, for example; the theme information of the poetry text to be trained can be obtained through theme analysis, for example; and so on, the analysis methods of the theme word information, rhyme information, style information and emotional information of the poetry text to be trained will not be repeated.
[0081] As an example, the poem text to be trained is "The moonlight shines brightly before my bed, I wonder if it is frost on the ground; I look up at the bright moon, and lower my head and think of my hometown." The fine-grained attribute information of the poem text to be trained is analyzed as "Type = five-character quatrain; Theme = homesickness; Theme word = moonlight; Theme word = hometown; Theme word = bright moon; Sentence 1 = moonlight; Sentence 2 = frost; Sentence 3 = bright moon; Sentence 4 = hometown; Rhyme = high; Style = plain; Emotion = slightly sad".
[0082] Step 203: Based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, train the preset language model to obtain the poetry generation model.
[0083] In an embodiment of the present application, after obtaining the training data of the model in steps 201-203, which are the poetry text to be trained and the fine-grained attribute information of the poetry text to be trained, on this basis, it is necessary to train a preset language model through the training data, that is, a preset language model, to fully explore the fine-grained attribute information of the poetry text to be trained and the correlation information between the poetry text to be trained, and after multiple iterative training with a large amount of training data, a poetry generation model can be obtained, which is used to generate poetry text according to the fine-grained attribute information of the poetry text.
[0084] When step 203 is specifically implemented, first, the fine-grained attribute information of the poetry text to be trained needs to be input into the preset language model, and the preset language model can generate a poetry text and output it as the first generated poetry text; then, it is necessary to use the preset poetry text loss function, that is, the preset poetry text loss function, to calculate the loss of the first generated poetry text and the poetry text to be trained to adjust the parameters of the preset language model; perform multiple iterative training until the preset number of iterative training times is reached or the preset language model converges, complete the training of the preset language model, and use the trained preset language model as the poetry generation model. Therefore, in an optional implementation of the embodiment of the present application, step 203 may, for example, include the following steps:
[0085] Step A: inputting the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text;
[0086] Step B: adjusting the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and the preset poetry text loss function;
[0087] Step C: Using the trained preset language model as the poetry generation model.
[0088] Among them, the preset language model can be, for example, a GPT model or other language models such as a recurrent neural network (English: Recurrent Neural Network, abbreviated as: RNN). Among them, the GPT model performs better in text generation, and the text it generates exceeds people's expectations of the language model at this stage in terms of contextual coherence and emotional expression; setting it as the preset language model is better than other language models such as RNN. Therefore, in an optional implementation of the embodiment of the present application, the preset language model is specifically a generative pre-trained language GPT model, especially a GPT2 model, a GPT3 model, and the like.
[0089] As an example, Figure 3 The schematic diagram of a training framework for a poetry generation model shown in FIG. 1 shows a training framework for a poetry generation model. Based on the above example, the fine-grained attribute information of the poetry text to be trained is "type = five-character quatrain; theme = homesickness; theme word = moonlight; theme word = hometown; theme word = bright moon; sentence 1 = moonlight; sentence 2 = frost; sentence 3 = bright moon; sentence 4 = hometown; rhyme = high; style = plain; emotion = slightly sad" is input into a preset language model, specifically a GPT2 model, to obtain the first generated poetry text. Based on the first generated poetry text, the poetry text to be trained "The moonlight in front of the bed is bright, I wonder if it is frost on the ground; I look up at the bright moon, and I look down and think of my hometown." and the preset poetry text loss function, the parameters of the preset language model are adjusted. The trained preset language model is used as the poetry generation model.
[0090] Through the various implementation methods provided in this embodiment, the poem text to be trained is obtained, the fine-grained attribute information of the poem text to be trained is analyzed, and based on the fine-grained attribute information of the poem text to be trained and the poem text to be trained, a preset language model is trained to obtain a poem generation model. It can be seen that when training to obtain a poem generation model, not only the poem is used as training data, but also the fine-grained attribute information of the poem itself is added as training data. This method fully mines the association information between the fine-grained attribute information of the poem text to be trained and the poem text to be trained, so that the poem generation model can achieve fine-grained attribute control when generating poems through the fine-grained attribute information of the poem itself.
[0091] On the basis of the above embodiments, since the trained poetry generation model is used to generate poetry text according to the fine-grained attribute information of the poetry text, the fine-grained attribute information required for the poetry text to be generated is first determined, and then the data is input into the poetry generation model to generate a poetry text and output it as the target poetry text. Compared with the poems generated by the planning-implementation method or the words generated by the GPT model in the prior art, the target poetry text has higher attribute controllability and more detailed.
[0092] See also Figure 4 , shows a flow chart of a method for generating poetry in an embodiment of the present application. In this embodiment, the method may include the following steps:
[0093] Step 401: Determine the fine-grained attribute information of the poem text to be generated.
[0094] Referring to the description of the above embodiment, the fine-grained attributes of the poem itself generally refer to the type, theme, keyword, rhyme, style and emotion of the poem. Therefore, in an optional implementation of the embodiment of the present application, the fine-grained attribute information includes at least two of type information, theme information, keyword information, rhyme information, style information and emotion information. As an example, the fine-grained attribute information of the poem text to be generated is "type = five-character quatrain; theme = homesickness".
[0095] Step 402: Based on the fine-grained attribute information of the poem text to be generated and the poem generation model, obtain the target poem text.
[0096] In the embodiment of the present application, in order to enable the poetry generation model to generate better poetry text, after determining the fine-grained attribute information of the poetry text to be generated in step 401, the fine-grained attribute information can also be expanded to obtain a higher-level expression of the fine-grained attribute information, as the extended information of the fine-grained attribute information of the poetry text to be generated, so as to perform higher-level attribute control when generating poetry in step 402. Therefore, in an optional implementation of the embodiment of the present application, after step 401 and before step 402, for example, step D can also be included: obtaining the extended information of the fine-grained attribute information of the poetry text to be generated.
[0097] Among them, the expansion method can be, for example, to pre-mine the fine-grained attribute information of historical poetry texts to form a poetry attribute knowledge base, search the poetry attribute knowledge base for attribute information that matches the fine-grained attribute information of the poetry text to be generated as the matching result; and use the attribute information in the matching result that is different from the fine-grained attribute information of the poetry text to be generated as the extended information. Therefore, in an optional implementation of the embodiment of the present application, the step D can, for example, include the following steps:
[0098] Step D1: Matching is performed in a poetry attribute knowledge base according to the fine-grained attribute information of the poetry text to be generated; wherein the poetry attribute knowledge base is obtained according to the fine-grained attribute information of the historical poetry texts mined in advance.
[0099] Step D2: Use the matching result of the fine-grained attribute information different from the poem text to be generated as the extended information.
[0100] As an example, the fine-grained attribute information of the poetry text to be generated is "theme = homesickness", and its extended information can be "theme word = hometown; theme word = local accent; theme word = moonlight; theme word = heartbroken; rhyme = Ang (Jiangyang rhyme); rhyme = Huizi rhyme (Huidui rhyme); emotion = uplifting; emotion = sad; style = plain; style = quiet".
[0101] As can be seen from the above description, correspondingly, after obtaining the fine-grained attribute information and its extended information of the poem text to be generated, different attribute controls can be implemented when generating poems in step 402. The required information can be selected from the fine-grained attribute information and its extended information of the poem text to be generated as the input control information of the poem text to be generated; the data is input into the poem generation model, and another poem text can be generated and output as the target poem text. The step 402 may, for example, include the following steps:
[0102] Step E: Selecting input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information;
[0103] Step F: Input the input control information into the poetry generation model to obtain the target poetry text.
[0104] As an example, the input control information of the poetry text to be generated is "Type = Five-character quatrain; Theme = Separation; Hide = One; Hide 2 = First; Hide 3 = Good; Hide 4 = Poem; Sentence 1 = Wind; Sentence 2 = End of the World; Sentence 3 = Xiao Xiao Ming (name); Sentence 4 = Drunk", which is input into the poetry generation model to obtain a generated poetry text "The wind and objects are different for a while; The first place is the end of the world; It's like Xiao Xiao Ming; The poem is like a drunken snake" as the target poetry text.
[0105] In addition, in an embodiment of the present application, each time step E to step F is executed, when the input control information of the selected poetry text to be generated is different, different third generated poetry texts can be generated as target poetry texts, that is, on the basis of the fine-grained attribute information of the poetry text to be generated and its extended information, different poetry texts can be generated and output by controlling the input information of the poetry generation model differently.
[0106] Through the various implementation methods provided in this embodiment, based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, a preset language model is pre-trained to obtain a poetry generation model; the fine-grained attribute information of the poetry text to be generated is determined; based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model, the target poetry text is obtained. It can be seen that by determining the fine-grained attribute information of the poetry itself and using a relatively simple model, fine-grained attribute control can be performed when generating poetry, making the attribute control more detailed, thereby improving the attribute controllability when generating poetry.
[0107] Exemplary Devices
[0108] See also Figure 5 , shows a schematic diagram of the structure of a device for generating poetry in an embodiment of the present application. In this embodiment, the device may specifically include:
[0109] A determination unit 501, used to determine fine-grained attribute information of the poem text to be generated;
[0110] A first obtaining unit 502 is used to obtain a target poem text based on the fine-grained attribute information of the poem text to be generated and the poem generation model;
[0111] The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and a preset language model pre-trained for the poetry text to be trained.
[0112] In an optional implementation manner of the embodiment of the present application, the device further includes:
[0113] An acquisition unit, used for acquiring the poem text to be trained;
[0114] An analysis unit, used for analyzing the fine-grained attribute information of the poem text to be trained;
[0115] A training unit is used to train the preset language model to obtain the poetry generation model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained.
[0116] In an optional implementation of the embodiment of the present application, the training unit includes:
[0117] A first obtaining subunit is used to input the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text;
[0118] An adjustment subunit, configured to adjust the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and a preset poetry text loss function;
[0119] The first is a subunit, which is used to use the trained preset language model as the poetry generation model.
[0120] In an optional implementation of the embodiment of the present application, the preset language model is specifically a generative pre-trained language GPT model.
[0121] In an optional implementation of the embodiment of the present application, the fine-grained attribute information includes at least two of type information, theme information, keyword information, rhyme information, style information and sentiment information.
[0122] In an optional implementation manner of the embodiment of the present application, the device further includes:
[0123] A second obtaining unit is used to obtain extended information of the fine-grained attribute information of the poem text to be generated;
[0124] Correspondingly, the first obtaining unit 502 includes:
[0125] A selection subunit, used to select input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information;
[0126] The second acquisition subunit is used to input the input control information into the poetry generation model to obtain the target poetry text.
[0127] In an optional implementation manner of the embodiment of the present application, the second obtaining unit includes:
[0128] A matching subunit, used for matching the fine-grained attribute information of the poem text to be generated in a poem attribute knowledge base; wherein the poem attribute knowledge base is obtained based on the fine-grained attribute information of the historical poem text mined in advance;
[0129] The second subunit is used to use the matching result of the fine-grained attribute information different from the poem text to be generated as the extended information.
[0130] Through the various implementation methods provided in this embodiment, based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, a preset language model is pre-trained to obtain a poetry generation model; the fine-grained attribute information of the poetry text to be generated is determined; based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model, the target poetry text is obtained. It can be seen that by determining the fine-grained attribute information of the poetry itself and using a relatively simple model, fine-grained attribute control can be performed when generating poetry, making the attribute control more detailed, thereby improving the attribute controllability when generating poetry.
[0131] Figure 66 is a block diagram of a device 600 for poetry generation according to an exemplary embodiment. For example, the device 600 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0132] Reference Figure 6 , the device 600 may include one or more of the following components: a processing component 602 , a memory 604 , a power component 606 , a multimedia component 608 , an audio component 610 , an input / output (I / O) interface 612 , a sensor component 614 , and a communication component 616 .
[0133] The processing component 602 generally controls the overall operation of the device 600, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 602 may include one or more processors 620 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 602 may include one or more modules to facilitate the interaction between the processing component 602 and other components. For example, the processing component 602 may include a multimedia module to facilitate the interaction between the multimedia component 608 and the processing component 602.
[0134] The memory 604 is configured to store various types of data to support operations on the device 600. Examples of such data include instructions for any application or method operating on the device 600, contact data, phone book data, messages, pictures, videos, etc. The memory 604 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0135] The power supply component 606 provides power to the various components of the device 600. The power supply component 606 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 600.
[0136] The multimedia component 608 includes a screen that provides an output interface between the device 600 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 608 includes a front camera and / or a rear camera. When the device 600 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0137] The audio component 610 is configured to output and / or input audio signals. For example, the audio component 610 includes a microphone (MIC), and when the device 600 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 604 or sent via the communication component 616. In some embodiments, the audio component 610 also includes a speaker for outputting audio signals.
[0138] I / O interface 612 provides an interface between processing component 602 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0139] The sensor assembly 614 includes one or more sensors for providing various aspects of status assessment for the device 600. For example, the sensor assembly 614 can detect the open / closed state of the device 600, the relative positioning of components, such as the display and keypad of the device 600, and the sensor assembly 614 can also detect the position change of the device 600 or a component of the device 600, the presence or absence of user contact with the device 600, the orientation or acceleration / deceleration of the device 600, and the temperature change of the device 600. The sensor assembly 614 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 614 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 614 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0140] The communication component 616 is configured to facilitate wired or wireless communication between the device 600 and other devices. The device 600 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 616 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 616 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0141] In an exemplary embodiment, the apparatus 600 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above methods.
[0142] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 604 including instructions, and the instructions can be executed by a processor 620 of the device 600 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0143] A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of a mobile terminal, enables the mobile terminal to perform a method for generating poetry, the method comprising:
[0144] Determine fine-grained attribute information of the poem text to be generated;
[0145] Based on the fine-grained attribute information of the to-be-generated poetry text and the poetry generation model, a target poetry text is obtained;
[0146] The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and a preset language model pre-trained for the poetry text to be trained.
[0147] Optionally, the training steps of the poetry generation model include:
[0148] Obtain the poem text to be trained;
[0149] Analyzing the fine-grained attribute information of the poem text to be trained;
[0150] Based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, the preset language model is trained to obtain the poetry generation model.
[0151] Optionally, the step of training the preset language model to obtain the poetry generation model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained includes:
[0152] Inputting the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text;
[0153] Adjusting the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and the preset poetry text loss function;
[0154] The trained preset language model is used as the poetry generation model.
[0155] Optionally, the preset language model is specifically a generative pre-trained language GPT model.
[0156] Optionally, the fine-grained attribute information includes at least two of type information, theme information, keyword information, rhyme information, style information and sentiment information.
[0157] Optionally, also include:
[0158] Obtaining extended information of the fine-grained attribute information of the poem text to be generated;
[0159] Correspondingly, the method of obtaining a target poetry text based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model includes:
[0160] Selecting input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information;
[0161] The input control information is input into the poetry generation model to obtain the target poetry text.
[0162] Optionally, the step of obtaining extended information of the fine-grained attribute information of the poem text to be generated includes:
[0163] According to the fine-grained attribute information of the poem text to be generated, matching is performed in a poem attribute knowledge base; wherein the poem attribute knowledge base is obtained based on the fine-grained attribute information of historical poem texts mined in advance;
[0164] The matching result of the fine-grained attribute information different from the poem text to be generated is used as the extended information.
[0165] Figure 77 is a schematic diagram of the structure of the server in the embodiment of the present application. The server 700 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 722 (for example, one or more processors) and a memory 732, and one or more storage media 730 (for example, one or more mass storage devices) storing application programs 742 or data 744. Among them, the memory 732 and the storage medium 730 can be temporary storage or permanent storage. The program stored in the storage medium 730 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 722 can be configured to communicate with the storage medium 730 and execute a series of instruction operations in the storage medium 730 on the server 700.
[0166] The server 700 may also include one or more power supplies 726, one or more wired or wireless network interfaces 750, one or more input and output interfaces 758, one or more keyboards 756, and / or one or more operating systems 741, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0167] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0168] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0169] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprises a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0170] The above is only a preferred embodiment of the present application and does not constitute any formal limitation to the present application. Although the present application has been disclosed as above with a preferred embodiment, it is not intended to limit the present application. Any technician familiar with the art can make many possible changes and modifications to the technical solution of the present application using the methods and technical contents disclosed above without departing from the scope of the technical solution of the present application, or modify it into an equivalent embodiment of equivalent changes. Therefore, any simple modification, equivalent change and modification made to the above embodiments based on the technical essence of the present application without departing from the content of the technical solution of the present application still fall within the scope of protection of the technical solution of the present application.
Claims
1. A method for generating poetry, characterized in that: include: Determine fine-grained attribute information of the poem text to be generated; the fine-grained attribute information includes type information, theme information, keyword information, rhyme information, style information and emotion information of the poem, and the type information includes the type of five-character quatrain; Based on the fine-grained attribute information of the to-be-generated poetry text and the poetry generation model, a target poetry text is obtained; The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and the preset language model pre-trained by the poetry text to be trained; According to the fine-grained attribute information of the poem text to be generated, matching is performed in a poem attribute knowledge base; the poem attribute knowledge base is obtained based on the fine-grained attribute information of historical poem texts mined in advance; The matching result of the fine-grained attribute information different from the poem text to be generated is used as extended information; the extended information includes subject word extended information, emotion extended information, style extended information and rhyme extended information, and the hierarchical expression of the extended information is higher than the hierarchical expression of the fine-grained attribute information; Correspondingly, the method of obtaining a target poetry text based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model includes: Selecting input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information; The input control information is input into the poetry generation model to obtain the target poetry text, wherein the target poetry text includes an acrostic poetry text.
2. The method according to claim 1, characterized in that The training steps of the poetry generation model include: Obtain the poem text to be trained; Analyzing the fine-grained attribute information of the poem text to be trained; Based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained, the preset language model is trained to obtain the poetry generation model.
3. The method according to claim 2, characterized in that The step of training the preset language model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained to obtain the poetry generation model includes: Inputting the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text; Adjusting the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and the preset poetry text loss function; The trained preset language model is used as the poetry generation model.
4. The method according to any one of claims 1 to 3, characterized in that The preset language model is specifically a generative pre-trained language GPT model.
5. A device for generating poetry, characterized in that: include: A determination unit, used to determine fine-grained attribute information of the poem text to be generated; the fine-grained attribute information includes type information, theme information, keyword information, rhyme information, style information and emotion information of the poem, and the type information includes the type of five-character quatrain; A first obtaining unit is used to obtain a target poetry text based on the fine-grained attribute information of the poetry text to be generated and a poetry generation model; wherein the poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and a pre-trained preset language model of the poetry text to be trained; A second obtaining unit is used to obtain extended information of the fine-grained attribute information of the poem text to be generated, wherein the extended information includes subject word extended information, emotion extended information, style extended information and rhyme extended information; Correspondingly, the first obtaining unit includes: A selection subunit, used to select input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information; A second obtaining subunit is used to input the input control information into the poetry generation model to obtain the target poetry text, wherein the target poetry text includes an acrostic poetry text; The second obtaining unit comprises: A matching subunit, used for matching the fine-grained attribute information of the poem text to be generated in a poem attribute knowledge base; wherein the poem attribute knowledge base is obtained based on the fine-grained attribute information of the historical poem text mined in advance; The second subunit is used to use the matching result of the fine-grained attribute information different from the poem text to be generated as the extended information.
6. The device according to claim 5, characterized in that The device also includes: An acquisition unit, used for acquiring the poem text to be trained; An analysis unit, used for analyzing the fine-grained attribute information of the poem text to be trained; A training unit is used to train the preset language model to obtain the poetry generation model based on the fine-grained attribute information of the poetry text to be trained and the poetry text to be trained.
7. The device according to claim 6, characterized in that The training unit comprises: A first obtaining subunit is used to input the fine-grained attribute information of the poem text to be trained into the preset language model to obtain a first generated poem text; An adjustment subunit, configured to adjust the parameters of the preset language model based on the first generated poetry text, the poetry text to be trained and a preset poetry text loss function; The first is a subunit, which is used to use the trained preset language model as the poetry generation model.
8. The device according to any one of claims 5 to 7, characterized in that: The preset language model is specifically a generative pre-trained language GPT model.
9. A device for poetry generation, characterized in that: The system comprises a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations: Determine fine-grained attribute information of the poem text to be generated; the fine-grained attribute information includes type information, theme information, keyword information, rhyme information, style information and emotion information of the poem; Based on the fine-grained attribute information of the to-be-generated poetry text and the poetry generation model, a target poetry text is obtained; The poetry generation model is obtained based on the fine-grained attribute information of the poetry text to be trained and the preset language model pre-trained by the poetry text to be trained; According to the fine-grained attribute information of the poem text to be generated, matching is performed in a poem attribute knowledge base; the poem attribute knowledge base is obtained based on the fine-grained attribute information of historical poem texts mined in advance; The matching result of the fine-grained attribute information different from the poem text to be generated is used as extended information; the extended information includes subject word extended information, emotion extended information, style extended information and rhyme extended information, and the hierarchical expression of the extended information is higher than the hierarchical expression of the fine-grained attribute information; Correspondingly, the method of obtaining a target poetry text based on the fine-grained attribute information of the poetry text to be generated and the poetry generation model includes: Selecting input control information of the poem text to be generated from the fine-grained attribute information of the poem text to be generated and the extended information; The input control information is input into the poetry generation model to obtain the target poetry text, wherein the target poetry text includes an acrostic poetry text.
10. A machine-readable medium having instructions stored thereon, which, when executed by one or more processors, causes the device to perform the method for generating poetry as described in any one of claims 1 to 4.
