Method, device, equipment and storage medium for generating poetry
By extracting features from various types of data input by users and generating poetry paragraphs in a step-by-step manner, the problem of low user participation in the existing technology is solved, and high user participation and flexibility in the poetry generation process are achieved.
Patent Information
- Application Number
- CN202310110868.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-09
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2043-02-09
AI Technical Summary
The existing poetry generation system has a problem of low user participation due to the single input information.
By extracting features from various types of data input by the user, using a preset poetry generation model and a preset alignment corpus, poetry paragraphs are generated step by step, and spliced together when the preset requirements are met to generate the target poetry.
It enhances the user's sense of participation in the poetry generation process, allows users to input a variety of data types, and review and adjust them during the generation process until they are satisfied, thus improving the user experience.
Smart Images

Figure CN116306518B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and more specifically, to a method, apparatus, device, and storage medium for generating poetry. Background Art
[0002] Poetry is the most common of all literary genres, encompassing a range of genres, including Tang poetry, Song lyrics, and Yuan opera, that express emotions in concise language. Poetry generation is an important entry point for studying how computers can automatically analyze, understand, and use human language.
[0003] Existing poetry generation systems typically aim to generate poetry based on user input. This requires the system to extract and summarize key information or features from the input, then feed them into the poetry generation model to guide the generation process. With the advancement of deep learning, poetry generation models based on recurrent neural networks and their variants have become widely used. In recent years, poetry generation models based on language models have essentially achieved the ability to generate high-quality poetry based on user-provided text.
[0004] However, this generation method has a relatively simple input information and directly generates the entire poem based on the information input by the user, resulting in low user participation. Summary of the Invention
[0005] The purpose of this application is to provide a method, device, equipment and storage medium for generating poetry in response to the above-mentioned deficiencies in the prior art, so as to solve the problem of low user participation in the prior art.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of the present application are as follows:
[0007] In a first aspect, an embodiment of the present application provides a method for generating poetry, the method comprising:
[0008] Performing feature extraction on at least one type of data input by the user, and determining first discrete vector features corresponding to each of the at least one type of data;
[0009] Generate a poem paragraph using a preset poem generation model based on the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus;
[0010] Determine whether all currently generated poetry paragraphs meet the paragraph requirements corresponding to the preset poetry type;
[0011] If so, the target poem is generated based on all the poem paragraphs.
[0012] In a second aspect, another embodiment of the present application provides a device for generating poetry, the device comprising: a determination module and a generation module, wherein:
[0013] The determining module is configured to perform feature extraction on at least one type of data input by the user, and respectively determine a first discrete vector feature corresponding to each of the at least one type of data;
[0014] The generation module is configured to generate a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus;
[0015] The determination module is specifically used to determine whether all currently generated poetry paragraphs meet the paragraph requirements corresponding to the preset poetry type;
[0016] The generation module is specifically used to generate target poems based on all the poem paragraphs.
[0017] In the third aspect, another embodiment of the present application provides a poetry generation device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the poetry generation device is running, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to perform the steps of any method described in the first aspect above.
[0018] In a fourth aspect, another embodiment of the present application provides a storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of any method described in the first aspect are executed.
[0019] The beneficial effect of the present application is that: by adopting the poetry generation method provided by the present application, the user can not only input at least one type of data, which greatly enhances the user's sense of participation in poetry generation, but also the preset poetry generation model can generate each poetry paragraph in the target poetry in a step-by-step manner. During the generation process, not only the first discrete vector feature corresponding to at least one type of data input by the user will be considered, but also the second discrete vector feature of the generated poetry will be considered, and poetry paragraphs will be generated based on the first discrete vector feature and the second discrete vector feature. When the sum of all generated poetry paragraphs reaches the paragraph requirement corresponding to the preset poetry type, all generated poetry paragraphs will be spliced to obtain the target poetry. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 A flowchart of a method for generating poetry provided in one embodiment of the present application;
[0022] Figure 2 A schematic diagram of a flow chart of a method for generating poetry provided in another embodiment of the present application;
[0023] Figure 3 A schematic diagram of a flow chart of a method for generating poetry provided in another embodiment of the present application;
[0024] Figure 4 A schematic diagram of a flow chart of a method for generating poetry provided in another embodiment of the present application;
[0025] Figure 5 A schematic diagram of the structure of a device for generating poetry provided in one embodiment of the present application;
[0026] Figure 6 A schematic structural diagram of a device for generating poetry provided in another embodiment of the present application;
[0027] Figure 7 A schematic diagram of the structure of a poetry generation device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in combination 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.
[0029] The components of the embodiments of the present application generally described and illustrated in the drawings herein may be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed application, but rather merely represents selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative effort are within the scope of protection of the present application.
[0030] In addition, the flowcharts used in this application illustrate operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowcharts may not be implemented in order, and steps that have no logical contextual relationship may be reversed or performed simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or may remove one or more operations from the flowcharts.
[0031] The following is an explanation of a poetry generation method provided in an embodiment of the present application in combination with multiple specific application examples.
[0032] In a possible implementation, the present invention provides a method for generating poetry. Figure 1 A flow chart of a method for generating poetry provided in one embodiment of the present application is shown as follows: Figure 1 As shown, the method includes:
[0033] S101: performing feature extraction on at least one type of data input by a user, and determining first discrete vector features corresponding to each of the at least one type of data.
[0034] In some possible embodiments, if at least one type of data includes keyword data, no processing is required at this time, and the keyword data itself is directly obtained as the first discrete vector feature corresponding to the keyword data; if at least one type of data includes text data, keyword extraction is performed on the text data, and the extracted keywords are determined to be the first discrete vector features corresponding to the text data.
[0035] If at least one type of data includes non-text data, where the non-text data may be, for example, image data, video data, or voice data, the non-text data is converted into text to obtain a text description corresponding to the non-text data; keywords are extracted from the text description, and the extracted keywords are determined to be the first discrete vector features corresponding to the non-text data.
[0036] In an embodiment of the present application, the method of extracting keywords from text descriptions and text data can be, for example, to extract keywords based on a preset word segmentation library. For example, when the text descriptions and text data are both Chinese data, keywords can be extracted based on a preset Chinese word segmentation library.
[0037] This setting allows users to input data from multiple sources, that is, different types of data. For example, users can input image data and text data at the same time, which greatly increases the user's sense of participation in generating the target poem and avoids the problem of only being able to receive and obtain a single data at a time. In addition, the present application converts different types of data into text data first, that is, unifies the format of different types of data, and then extracts keywords from the text data from multiple sources, so that more first discrete vector features can be obtained, so that more features can be referenced when subsequently generating poem paragraphs, and the generated poem paragraphs are more likely to meet user expectations.
[0038] S102: Generate a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus.
[0039] In an embodiment of the present application, before generating a paragraph of poetry, it is also necessary to perform feature extraction on the poetry generated in the process of generating the target poetry, and determine the second discrete vector features corresponding to the generated poetry. The extraction method is the same as the feature extraction method provided in the S101 embodiment. Since the generated poetry is text data, keywords can be directly extracted from it, and the extracted keywords are determined to be the second discrete vector features corresponding to the generated poetry.
[0040] In an embodiment of the present application, a preset poetry generation model can be used to generate a preset number (one or more paragraphs) of poetry paragraphs at a time. If the user is not satisfied with the currently generated poetry paragraph, the poetry paragraph corresponding to at least one type of data currently input can be regenerated by triggering a regeneration operation until the generated poetry paragraph meets the user's requirements. The method of triggering the regeneration operation can, for example, be: triggered by the user through a preset control, or generated by the user through a preset shortcut, or triggered by the user through a preset shortcut key. The specific method of triggering the regeneration of the poetry paragraph can be flexibly adjusted according to user needs and is not limited to the above embodiments.
[0041] This setting method allows users to review and adjust each poetry paragraph according to their own ideas, avoiding the problem that users cannot change the generated poetry paragraphs, and further improving the user experience.
[0042] S103: Determine whether all currently generated poetry paragraphs meet the paragraph requirements corresponding to the preset poetry type.
[0043] In an embodiment of the present application, different preset poetry types may correspond to different paragraph requirements, wherein the segmentation logic is to segment the poetry according to punctuation marks other than commas (","), such as: ".", "!", ";", etc.; for example, for a poem whose preset poetry type is a five-character quatrain, the corresponding paragraph requirement may be, for example, five paragraphs of poetry; for a poem whose preset poetry type is a seven-character regulated verse, the corresponding paragraph requirement may be, for example, seven paragraphs of poetry; for a poem whose preset poetry type is Song poetry, the corresponding paragraph requirement may be, for example, four paragraphs of poetry; it should be understood that the correspondence between the specific preset poetry type and the paragraph requirements is pre-configured and stored in the database. After obtaining the preset poetry type input by the user, the paragraph requirement corresponding to the preset poetry type can be determined. The specific correlation between the preset poetry type and the paragraph requirement and the type of the preset poetry can be flexibly adjusted according to user needs and are not limited to those given in the above embodiments.
[0044] In some possible embodiments, the preset poetry type can be input by the user, that is, the user can input the preset poetry type as the target poetry type according to his or her expectations for the target poetry; or, in other possible embodiments, when the user prefers to receive random target poetry, he or she can select a random type when determining the type of the target poetry. Subsequently, before the preset poetry generation model generates the target poetry, the preset poetry generation model first randomly selects a poetry type from the multiple poetry types stored in the database as the poetry type corresponding to the target poetry, and generates subsequent poetry paragraphs based on the relevant information corresponding to the poetry type to generate the target poetry.
[0045] If not, it means that the total number of poetry paragraphs currently generated does not meet the paragraph requirements corresponding to the preset poetry type. At this time, repeat the above steps S101-S102 until the total number of poetry paragraphs generated meets the paragraph requirements corresponding to the preset poetry type.
[0046] If so, it means that the total number of currently generated poetry paragraphs meets the paragraph requirements corresponding to the preset poetry type, and S104 is executed at this time.
[0047] S104: Generate target poems based on all poem paragraphs.
[0048] In an embodiment of the present application, all the poem paragraphs are spliced in the order in which they are generated, and the poem obtained after the splicing is completed is the complete target poem.
[0049] By adopting the poetry generation method provided in the present application, users can not only input at least one type of data, which greatly enhances the user's sense of participation in poetry generation, but also the preset poetry generation model can generate each poetry paragraph in the target poetry in a step-by-step manner. During the generation process, not only the first discrete vector feature corresponding to at least one type of data input by the user will be considered, but also the second discrete vector feature of the generated poetry will be considered, and poetry paragraphs will be generated based on the first discrete vector feature and the second discrete vector feature. When the sum of all generated poetry paragraphs reaches the paragraph requirement corresponding to the preset poetry type, all generated poetry paragraphs will be spliced to obtain the target poetry.
[0050] Optionally, based on the above embodiment, the embodiment of the present application can also provide a method for generating poetry. The implementation process of the above method is illustrated below with reference to the accompanying drawings. Figure 2 A flow chart of a method for generating poetry provided in another embodiment of the present application is shown as follows: Figure 2 As shown, before S101, the method may further include:
[0051] S111: Segment each poem sample in the poem sample set, and generate segmented alignment data corresponding to each poem sample.
[0052] In an embodiment of the present application, the method of segmenting each poetry sample can be, for example, first performing sentence processing on each poetry sample according to preset punctuation marks, for example, performing sentence processing on each poetry sample according to a comma (",") and / or a period ("."), and after the sentence processing, performing segmentation processing on each poetry sample according to the sentence processing results.
[0053] For example, the poem "A thousand mountains are devoid of birds, and a thousand paths are deserted. A lone old man in a straw raincoat and straw hat is fishing alone in the snowy river." is segmented into four sentences: "A thousand mountains are devoid of birds," "A thousand paths are devoid of humans," "A lone old man in a straw raincoat and straw hat is fishing alone in the snowy river." The sentence segmentation results are then segmented based on periods ("."), where each period is a segmentation marker. After segmentation, the sentence sample is segmented into two sentences: "A thousand mountains are devoid of birds, and a thousand paths are devoid of humans," and "A thousand mountains are devoid of birds, and a thousand paths are devoid of humans."
[0054] Let’s take the above poem as an example. After segmentation, the generated aligned data is as follows: “(5) No birds fly in the thousands of mountains, [people, disappear] — No trace of people on the thousands of paths”; “(5) No birds fly in the thousands of mountains, (5) No trace of people on the thousands of paths. [Lonely boat] — An old man in a straw hat and raincoat in a lonely boat”; “(5) No birds fly in the thousands of mountains, (5) No trace of people on the thousands of paths. (5) An old man in a straw hat and raincoat in a lonely boat, [snow] — Fishing alone in the snow on the cold river”.
[0055] The content before the “——” symbol represents the previous context of the poem, and the content after the “——” symbol represents the following context of the poem. The content in “[]” contains keywords and other information about the following context of the poem. The content in “()” represents the length information of each poem line. In other words, the aligned data includes: multiple poem sample sub-paragraphs, the contextual relationship information between the multiple poem sample sub-paragraphs, and the length information corresponding to the multiple poem sample sub-paragraphs.
[0056] S112: Add the aligned data to the preset aligned corpus.
[0057] In an embodiment of the present application, the preset aligned corpus includes multiple poetry paragraphs. The multiple poetry paragraphs in the preset aligned corpus can be, for example, a large amount of poetry paragraph data crawled from the Internet. The poetry can be, for example, Tang poetry, Song poetry, Yuan opera, etc. After crawling is completed, the crawled poetry paragraph data needs to be cleaned, and then the cleaned poetry paragraph data is stored in the preset aligned corpus.
[0058] For example, the cleaning method may include, but is not limited to: filtering out URL information in poetry paragraph data, filtering out duplicate poetry paragraph data, filtering out poetry paragraph data with a word count less than a preset threshold, etc. It should be understood that the above embodiments are only exemplary, and the specific method of cleaning poetry paragraph data can be flexibly adjusted according to user needs and is not limited to the above embodiments.
[0059] Optionally, based on the above embodiment, the embodiment of the present application can also provide a method for generating poetry. The implementation process of the above method is illustrated below with reference to the accompanying drawings. Figure 3 A flow chart of a method for generating poetry provided in another embodiment of the present application is shown as follows: Figure 3 As shown, before S102, the method may further include:
[0060] S121: In response to the poetry type input by the user, determining the preset rhythm requirements corresponding to the poetry type.
[0061] Among them, different types of poems may have different preset rhythm requirements. The preset rhythm requirements are the correspondence between different types of poems and the preset rhythm requirements summarized after analyzing and processing each sample poem in the aforementioned sample poem set. After the summary is completed, the summarized correspondence needs to be stored in the preset database, so that after obtaining the type of poem input by the user, the corresponding rhythm requirements can be determined according to the poem type, thereby determining the tone of each paragraph of poetry in the subsequently generated target poem.
[0062] Correspondingly, S102 may include:
[0063] S122: Generate a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, the preset metrical requirements and the preset alignment corpus.
[0064] Optionally, based on the above embodiment, the embodiment of the present application can also provide a method for generating poetry. The following example illustrates the implementation process of generating poetry paragraphs in the above method in conjunction with the accompanying drawings. Figure 4 A flow chart of a method for generating poetry provided in another embodiment of the present application is shown as follows: Figure 4 As shown, S102 may include:
[0065] S131: Using a preset poetry generation model to splice the first discrete vector and the second discrete vector to obtain a spliced third discrete vector.
[0066] In an embodiment of the present application, after obtaining the first discrete vector and the second discrete vector, the first discrete vector and the second discrete vector can be directly horizontally spliced to obtain a third discrete vector with a higher dimension than the first discrete vector and the second discrete vector.
[0067] S132: Using a preset poetry generation model to reduce the dimension of the third discrete vector based on a preset linear grid, and generating a poetry paragraph according to the discrete vector after the dimension reduction.
[0068] In an embodiment of the present application, for example, the third discrete vector can be reduced in dimension based on a preset linear network to the dimension required by a preset poetry generation model, and a poetry paragraph can be generated based on the discrete vector after the dimensionality reduction.
[0069] In some possible embodiments, the preset linear network may be, for example, a multilayer perceptron (MLP), which converts the vector dimension according to preset dimensional information, and the preset dimensional information is the dimension required by the preset poetry generation model; for example, the dimension required by the preset poetry generation model is 769 dimensions, the dimension of the first discrete vector feature is 768 dimensions, and the dimension of the second discrete vector feature of the generated poetry is also 768 dimensions, then the dimension of the third discrete vector feature after horizontally splicing the first discrete vector feature and the second discrete vector feature is the dimension of the first discrete vector feature. The sum of the dimensions of the quantity feature and the second discrete vector feature, that is, the dimension of the third discrete vector feature is 1536 dimensions, that is, the input of the linear network is a 1536-dimensional feature vector. After being processed by the linear network, the dimension of the third discrete vector feature is reduced according to the required dimension of the preset poetry generation model. After the dimensionality reduction processing, the linear network outputs a feature vector with a feature dimension of 768 dimensions. It should be understood that the above embodiment is only an exemplary description. The specific preset type of linear network and the preset dimension required for the poetry generation model can be flexibly adjusted according to user needs and are not limited to the above embodiment.
[0070] In an embodiment of the present application, after generating the target poem, the user can also share it at will, for example, share the generated target poem to a social platform or share it on the Internet, and during the sharing process, the user can add the user's corresponding identification information based on the target poem. The identification information can be, for example, the user's name information, or the user's account information, or the user's customized information, etc., which can be flexibly adjusted according to the user's needs and is not limited to the above embodiments.
[0071] By adopting the poetry generation method provided by this application, users can generate the poems they want step by step, and splice the target poems based on the generated multiple paragraphs of poems. When generating each paragraph of poems, users can not only enter keywords, but also upload pictures, videos or articles as input data, which greatly increases the user's sense of participation in poetry generation. In the process of generating each paragraph of poems, if the user is not satisfied, it can be regenerated until the user is satisfied, so that each user can create vivid target poems that meet their needs.
[0072] The following is an explanation of the poetry generation device provided by this application with reference to the accompanying drawings. The poetry generation device can execute the above Figure 1-Figure 4 The specific implementation and beneficial effects of any method for generating poetry are as mentioned above and will not be repeated below.
[0073] Figure 5 A schematic diagram of the structure of a device for generating poetry provided in one embodiment of the present application is shown in FIG. Figure 5 As shown, the apparatus includes: a determination module 201 and a generation module 202, wherein:
[0074] The determination module 201 is configured to perform feature extraction on at least one type of data input by the user, and determine first discrete vector features corresponding to each type of data.
[0075] The generation module 202 is used to generate a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem and a preset alignment corpus.
[0076] The determination module 201 is specifically used to determine whether all currently generated poetry paragraphs meet the paragraph requirements corresponding to the preset poetry type.
[0077] The generation module 202 is specifically used to generate target poems based on all the poem paragraphs if yes.
[0078] Optionally, the determination module 201 is specifically used to extract features of the generated poems and determine the second discrete vector features corresponding to the generated poems.
[0079] Optionally, the generation module 202 is specifically used to segment each poetry sample in the poetry sample set and generate segmented alignment data corresponding to each poetry sample; wherein the alignment data includes: multiple poetry sample sub-paragraphs, contextual relationship information between multiple poetry sample sub-paragraphs and length information corresponding to multiple poetry sample sub-paragraphs; and the alignment data is added to the preset alignment corpus.
[0080] Optionally, based on the above embodiment, the embodiment of the present application can also provide a device for generating poetry, as shown below in conjunction with the accompanying drawings. Figure 5 The implementation process of the given device is described with an example. Figure 6 Another embodiment of the present application provides a schematic diagram of the structure of a device for generating poetry, such as Figure 6 As shown, the device further includes: an acquisition module 203, which is used to filter the poetry sample set and obtain the filtered poetry sample set.
[0081] Optionally, the determination module 201 is specifically configured to extract keywords from the text data if at least one type of data includes text data, and determine the extracted keywords as first discrete vector features corresponding to the text data.
[0082] Optionally, the acquisition module 203 is specifically configured to, if at least one type of data includes non-text data, convert the non-text data into text, and obtain a text description corresponding to the non-text data.
[0083] The determination module 201 is specifically configured to extract keywords from the text description and determine that the extracted keywords are first discrete vector features corresponding to the non-text data.
[0084] Optionally, the determination module 201 is specifically configured to determine a preset rhythm requirement corresponding to the poetry type in response to the poetry type input by the user.
[0085] The generation module 202 is specifically used to generate a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, the preset rhythm requirement and the preset alignment corpus.
[0086] like Figure 6 As shown, the device further includes: a processing module 204, which is used to perform sentence processing on each poem sample according to preset punctuation marks; and to perform segmentation processing on each poem sample according to the sentence processing result.
[0087] Optionally, the processing module 204 is specifically configured to use a preset poetry generation model to concatenate the first discrete vector and the second discrete vector to obtain a concatenated third discrete vector.
[0088] The generation module 202 is specifically configured to use a preset poetry generation model to reduce the dimension of the third discrete vector based on a preset linear grid, and generate a poetry paragraph according to the discrete vector after the dimension reduction.
[0089] The above-mentioned device is used to execute the method provided in the above-mentioned embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0090] The above modules can be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), one or more microprocessors, or one or more field programmable gate arrays (FPGAs). For another example, when a module is implemented by scheduling program code through a processing element, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0091] Figure 7 This is a structural diagram of a poetry generation device provided in one embodiment of the present application. The poetry generation device can be integrated into a terminal device or a chip of a terminal device.
[0092] like Figure 7 As shown, the poetry generation device includes: a processor 501, a bus 502 and a storage medium 503.
[0093] The processor 501 is used to store programs. The processor 501 calls the program stored in the storage medium 503 to execute the above Figure 1-Figure 4 The specific implementation and technical effects of the corresponding method embodiment are similar and will not be described in detail here.
[0094] Optionally, the present application also provides a program product, such as a storage medium, on which a computer program is stored, including a program that, when executed by a processor, executes an embodiment corresponding to the above method.
[0095] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0096] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0097] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0098] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (English: Read-Only Memory, abbreviated: ROM), a random access memory (English: Random Access Memory, abbreviated: RAM), a disk or an optical disk, and other media that can store program code.
Claims
1. A method for generating poetry, characterized in that: The method comprises: Performing feature extraction on at least one type of data input by the user, and determining first discrete vector features corresponding to each of the at least one type of data; Generate a poem paragraph using a preset poem generation model based on the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus; Determine whether all currently generated poetry paragraphs meet the paragraph requirements corresponding to the preset poetry type; If so, generate the target poem based on all the poem paragraphs; Before extracting features from at least one type of data input by the user and determining first discrete vector features corresponding to each of the at least one type of data, the method includes: Segmenting each poem sample in the poem sample set and generating segmented alignment data corresponding to each poem sample; wherein the alignment data includes: a plurality of poem sample subparagraphs, contextual relationship information between the plurality of poem sample subparagraphs, and length information corresponding to the plurality of poem sample subparagraphs; The alignment data is added to the preset alignment corpus.
2. The method according to claim 1, wherein Before generating a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus, the method further includes: Feature extraction is performed on the generated poem to determine a second discrete vector feature corresponding to the generated poem.
3. The method according to claim 1, wherein Before segmenting each poem sample in the poem sample set and generating segmented alignment data corresponding to each poem sample, the method further includes: Data filtering is performed on the poetry sample set to obtain a filtered poetry sample set.
4. The method according to claim 1, wherein The performing feature extraction on at least one type of data input by the user and respectively determining first discrete vector features corresponding to each of the at least one type of data includes: If the at least one type of data includes text data, keyword extraction is performed on the text data, and the extracted keywords are determined to be first discrete vector features corresponding to the text data.
5. The method according to claim 1, wherein The performing feature extraction on at least one type of data input by the user and respectively determining first discrete vector features corresponding to each of the at least one type of data includes: If the at least one type of data includes non-text data, converting the non-text data into text to obtain a text description corresponding to the non-text data; Keyword extraction is performed on the text description, and the extracted keyword is determined to be a first discrete vector feature corresponding to the non-text data.
6. The method according to claim 1, wherein Before generating a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus, the method further includes: In response to a poem type input by a user, determining a preset metrical requirement corresponding to the poem type; The method of using a preset poetry generation model to generate a poetry paragraph according to the first discrete vector feature, the second discrete vector feature of the generated poetry, and a preset alignment corpus includes: A preset poetry generation model is used to generate poetry paragraphs based on the first discrete vector features, the second discrete vector features of the generated poetry, the preset metrical requirements and the preset alignment corpus.
7. The method according to claim 1, wherein The segmentation processing of each poem sample in the poem sample set includes: Sentence processing is performed on each of the poetry samples according to preset punctuation marks; Each of the poetry samples is segmented according to the sentence segmentation results.
8. The method according to claim 1, wherein The method of using a preset poetry generation model to generate a poetry paragraph according to the first discrete vector feature, the second discrete vector feature of the generated poetry, and a preset alignment corpus includes: Using a preset poetry generation model to splice the first discrete vector and the second discrete vector to obtain a spliced third discrete vector; A preset poetry generation model is used to reduce the dimension of the third discrete vector based on a preset linear grid, and the poetry paragraph is generated according to the discrete vector after the dimension reduction.
9. A device for generating poetry, characterized in that: The device includes: a determination module and a generation module, wherein: The determining module is configured to perform feature extraction on at least one type of data input by the user, and respectively determine a first discrete vector feature corresponding to each of the at least one type of data; The generation module is configured to generate a poem paragraph using a preset poem generation model according to the first discrete vector feature, the second discrete vector feature of the generated poem, and a preset alignment corpus; The determination module is specifically used to determine whether all currently generated poetry paragraphs meet the paragraph requirements corresponding to the preset poetry type; The generating module is specifically configured to generate a target poem based on all the poem paragraphs if so; Among them, before the feature extraction of at least one type of data input by the user and the determination of the first discrete vector features corresponding to each of the at least one type of data, it also includes: segmenting each poetry sample in the poetry sample set, and generating segmented alignment data corresponding to each poetry sample; wherein the alignment data includes: multiple poetry sample sub-paragraphs, contextual relationship information between multiple poetry sample sub-paragraphs and length information corresponding to multiple poetry sample sub-paragraphs; and adding the alignment data to a preset alignment corpus.
10. A device for generating poetry, characterized in that: The device includes: a processor, a storage medium and a bus, the storage medium stores machine-readable instructions executable by the processor, and when the poetry generation device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to execute the method described in any one of claims 1 to 8.
11. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is executed.
Citation Information
Patent Citations
Method and apparatus for automatically generating poem
CN105955964A