Story text generation method and device, equipment and medium
Patent Information
- Application Number
- CN202310172194.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-21
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2043-02-21
AI Technical Summary
[0004]本发明的主要目的为提供一种故事文本的生成方法、装置、设备及介质,旨在解决现有自动生成的故事文本是由简单的文本构成,不具有跌宕起伏的剧情,使得故事文本的可读性较差的问题
[0049] The beneficial effects of this invention are as follows: by acquiring story tags and finding target stories to generate a directed cyclic graph, and using a preset encoding and decoder to generate story text, the generated story text has a similar dramatic plot to the target story, thereby improving the readability of the story text.
Smart Images

Figure CN116167358B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method, apparatus, device, and medium for generating story text. Background Technology
[0002] Natural language generation is a branch of computational linguistics and artificial intelligence. The corresponding language generation system is a computer model based on language information processing. It starts from the level of abstract concepts and generates text through certain semantic and grammatical rules. The text can be an insurance claim story.
[0003] The existing story texts mainly rely on the story background provided by relevant personnel. During the data processing, the generated story texts all depend on this story background, resulting in the generated story texts being composed of simple texts without dramatic plot twists, making the story texts less readable. Summary of the Invention
[0004] The main objective of this invention is to provide a method, apparatus, device, and medium for generating story text, aiming to solve the problem that existing automatically generated story texts consist of simple text, lack dramatic plot twists, and thus have poor readability.
[0005] This invention provides a method for generating story text, comprising:
[0006] Get the story tags for the story to be generated;
[0007] Retrieve the target story from a preset story database based on the story tags;
[0008] Extract verbs from the target story, and arrange the verbs according to their order in the target story to obtain the target verb set;
[0009] Construct a directed cyclic graph for all verbs in the target verb set; wherein each node in the directed cyclic graph consists of a verb.
[0010] The directed cyclic graph is input into a preset encoder to obtain the story code;
[0011] The story encoding and the story label are input into a preset decoder to obtain the story text. The preset encoder and the preset decoder are trained using multiple directed cyclic graphs, the corresponding story labels, and the corresponding stories.
[0012] Furthermore, the step of obtaining the story tags for the story to be generated includes:
[0013] Get the story image input by the user;
[0014] Feature information is extracted from the story images based on a preset VIT model;
[0015] Story tags are generated based on the aforementioned feature information.
[0016] Furthermore, the step of retrieving the target story from a preset story database based on the story tag includes:
[0017] Vectorize the story tags to obtain the multidimensional coordinates of the target vector X = (x1, x2, x3…x…). n ), where the target vector is the vector corresponding to the story tag;
[0018] According to the formula Calculate the similarity value between the story tag and the pre-stored vectors of each story in the preset story database, where Y is the multi-dimensional coordinate of each pre-stored vector in the story database, Y = (y1, y2, y3…y…). n );
[0019] The target story is selected based on the magnitude of the similarity value.
[0020] Furthermore, the target story includes multiple segments, and the step of extracting verbs from the target story and arranging the verbs according to their order in the target story to obtain a target verb set includes:
[0021] Extract verbs from multiple target stories and arrange them according to the order of each verb in the corresponding target story to obtain the verb set corresponding to each target story;
[0022] Select one set of verbs and denote it as the first set of verbs; denote the remaining sets of verbs as the second set of verbs.
[0023] Verbs from the second set of verbs are randomly selected and merged into the first set of verbs to obtain a temporary set of verbs. The merging methods include replacing verbs from the first set of verbs and adding verbs to the first set of verbs.
[0024] The reasonableness of the temporary verb set is calculated based on the coherence between verbs;
[0025] Determine whether the reasonableness is greater than a preset reasonable threshold;
[0026] If the value exceeds a preset reasonable threshold, the temporary verb set is recorded as the target verb set.
[0027] Furthermore, after the step of inputting the story encoding and the story tag into a preset decoder to obtain the story text, the method further includes:
[0028] A target sentence is randomly selected from the story text, and the target vectors corresponding to each sentence from the beginning of the story text to the end of the target sentence are weighted and summed to obtain a first vector. The target vectors corresponding to each sentence from the end of the target sentence to the end of the story text are weighted and summed to obtain a second vector. The dimension of the first vector is equal to the dimension of the second vector.
[0029] The similarity between the first vector and the second vector corresponding to the target sentence is calculated. The calculated first similarity value is then non-linearly mapped to the (0,1) interval using a sigmoid algorithm to find the linear distance with 1.
[0030] The linear distance is compared with a set threshold. When the linear distance is higher than the set threshold, the end of the target sentence is taken as the paragraph break point.
[0031] The target story is segmented based on the paragraph dividing points.
[0032] Further, the step of inputting the story encoding and the story tag into a preset decoder to obtain the story text includes:
[0033] The story code is split into multiple codes in sequence;
[0034] The codes are sequentially input into a preset decoder for decoding; wherein, the current encoding decoding operation is to input the hidden layer from the previous encoding decoding process, the story tag, and the current encoding into the preset decoder to obtain the decoding result of the current encoding;
[0035] By concatenating all the decoding results in order, the target story is obtained.
[0036] The present invention also provides a story text generation apparatus, comprising:
[0037] The first acquisition module is used to acquire the story tags of the story to be generated;
[0038] The second acquisition module is used to acquire target stories from a preset story database based on the story tags;
[0039] An extraction module is used to extract verbs from the target story and arrange the verbs according to their order in the target story to obtain a target verb set.
[0040] A construction module is used to construct a directed cyclic graph for all verbs in the target verb set; wherein each node in the directed cyclic graph is composed of a verb;
[0041] The first input module is used to input the directed cyclic graph into a preset encoder to obtain the story code;
[0042] The second input module is used to input the story encoding and the story label into a preset decoder to obtain the story text. The preset encoder and the preset decoder are trained by multiple directed cyclic graphs, the corresponding story labels, and the corresponding stories.
[0043] Further, the first acquisition module includes:
[0044] The `get` submodule is used to retrieve the story image input by the user;
[0045] The extraction submodule is used to extract feature information from the story images according to a preset VIT model;
[0046] A generation submodule is used to generate story tags based on the feature information.
[0047] The present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of any of the methods described above.
[0048] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any of the methods described above.
[0049] The beneficial effects of this invention are as follows: by acquiring story tags and finding target stories to generate a directed cyclic graph, and using a preset encoding and decoder to generate story text, the generated story text has a similar dramatic plot to the target story, thereby improving the readability of the story text. Attached Figure Description
[0050] Figure 1 This is a flowchart illustrating a method for generating story text according to an embodiment of the present invention;
[0051] Figure 2 This is a schematic block diagram of a story text generation device according to an embodiment of the present invention;
[0052] Figure 3 This is a schematic block diagram of the structure of a computer device according to an embodiment of this application.
[0053] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0054] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0055] It should be noted that all directional indicators (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicator will also change accordingly. The connection can be a direct connection or an indirect connection.
[0056] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, A and B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0057] Furthermore, in this invention, descriptions involving "first," "second," etc., are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature. Additionally, the technical solutions of the various embodiments can be combined with each other, but only on the basis of being achievable by those skilled in the art. When the combination of technical solutions is contradictory or impossible to implement, such a combination of technical solutions should be considered non-existent and not within the scope of protection claimed by this invention.
[0058] Reference Figure 1 This invention proposes a method for generating story text, comprising:
[0059] S1: Obtain the story tags for the story to be generated;
[0060] S2: Obtain the target story from the preset story database based on the story tags;
[0061] S3: Extract the verbs from the target story, and arrange the verbs according to their order in the target story to obtain the target verb set;
[0062] S4: Construct a directed cyclic graph for all verbs in the target verb set; wherein each node in the directed cyclic graph consists of a verb;
[0063] S5: Input the directed cyclic graph into a preset encoder to obtain the story code;
[0064] S6: Input the story encoding and the story label into the preset decoder to obtain the story text, wherein the preset encoder and the preset decoder are trained by multiple directed cyclic graphs, the corresponding story labels and the corresponding stories.
[0065] As described in step S1 above, the story tags of the story to be generated are obtained. The story tags are generated based on the content input by the user. The user can input a text title or an image. Then, the key information is extracted from the text title or title to form the story tags.
[0066] As described in step S2 above, the target story is obtained from the preset story database based on the story tag. This can be achieved by calculating the similarity between the story tag and each story in the preset story database. In a specific embodiment, a sufficient number of stories can be collected in advance as the preset story database. Topic clustering is then performed on the story data in the preset story database. Here, the commonly used k-means clustering method is used, where k is the number of topic types, which can be set manually. Then, the similarity between the story tag and each type is calculated to determine the type of the story tag. Then, the similarity between each story and the story tag is calculated from the corresponding type. This avoids calculating the similarity between the story tag and each story in the preset story database, saving certain computing resources.
[0067] As described in step S3 above, verbs are extracted from the target story, and the verbs are arranged according to their order in the target story to obtain the target verb set. The extraction method can be pre-processed using part-of-speech tagging, for example, by using Stanford POS to tag the data and extracting the verbs in the order they appear in the story to obtain the target verb set.
[0068] As described in step S4 above, a directed cyclic graph is constructed for all verbs in the target verb set. Each node in the directed cyclic graph consists of a verb. By constructing a directed cyclic graph for all verbs, the transition probability from event A to event B, i.e., the transition probability from one verb to another, can be calculated. This transition probability is an important concept in Markov chains. If a Markov chain consists of m states, historical data is transformed into a sequence composed of these m states. Starting from any state, after any transition, one of states 1, 2, ..., m will inevitably appear. This transition between states is called the transition probability.
[0069] As described in steps S5-S6 above, the directed cyclic graph is input into a preset encoder to obtain the story encoding. The story encoding and the story labels are then input into a preset decoder to obtain the story text. The preset encoder and preset decoder are trained using multiple directed cyclic graphs, corresponding story labels, and corresponding stories. It should be noted that the preset encoder is an LSTM (long short-term memory) model. The directed cyclic graph is input into the LSTM model for encoding. During decoding, the user's input features are also input as independent features to the preset decoder. Therefore, the input of the preset decoder at time t is:
[0070] 1. Features of the hidden layer state at the previous time step t-1;
[0071] 2. Word vector features of the output word at the previous time step t-1;
[0072] 3. User input characteristics (story theme text features or image features).
[0073] The LSTM decoder receives these three inputs at each time step, and its output is the predicted word for the current time step, which also becomes the input for the next time step. Finally, all the generated words are concatenated in order to form a story.
[0074] It's also important to note that the pre-defined encoder and decoder need to be trained synchronously during the training process. The specific training method is the same as that of a typical pre-defined encoder and decoder, using different directed cyclic graphs (DCRs) and their corresponding story texts as training data. This allows the generated story text to have a similar dramatic plot to the target story, improving readability. The pre-defined encoder encodes the DCR into an intermediate representation that is beneficial for machine learning. The pre-defined decoder is then trained based on this intermediate representation and the corresponding story labels. The corresponding stories are used to calculate the loss value generated by the pre-defined encoder and decoder. The parameters in the pre-defined encoder and decoder are continuously adjusted based on the loss value, thus completing the training of the pre-defined encoder and decoder. Specifically, the generated story text can be insurance claim stories, allowing readers to gain a more intuitive understanding of insurance claims.
[0075] In one embodiment, step S1 of obtaining the story tag for the story to be generated includes:
[0076] S101: Obtain the story image input by the user;
[0077] S102: Extract feature information from the story images according to the preset VIT model;
[0078] S103: Generate story tags based on the feature information.
[0079] As described in steps S101-S103 above, when the user inputs image information, a preset VIT model can be used for extraction. The VIT model is a large-scale CNN image recognition model open-sourced by Google that can effectively extract feature information from story images and generate story tags based on this feature information. Additionally, it should be noted that if the user inputs text information, the BERT model can be used to extract feature information, and then story tags can be generated based on this feature information. This achieves the generation of story tags, which can specifically include the amount of compensation, the type of insurance, etc.
[0080] In one embodiment, step S2, which involves retrieving the target story from a preset story database based on the story tag, includes:
[0081] S201: Vectorize the story tags to obtain the multidimensional coordinates X = (x1, x2, x3…x…) of the target vector. n ), where the target vector is the vector corresponding to the story tag;
[0082] S202: According to the formula Calculate the similarity value between the story tag and the pre-stored vectors of each story in the preset story database, where Y is the multi-dimensional coordinate of each pre-stored vector in the story database, Y = (y1, y2, y3…y…). n );
[0083] S203: Select the target story based on the magnitude of the similarity value.
[0084] As described in step S201 above, the story tags are vectorized to obtain the multidimensional coordinates of the target vector for subsequent calculations. The standardization question can be vectorized using the Google word2vec tool after word segmentation.
[0085] As described in steps S202-S203 above, according to the formula:
[0086] Calculate the similarity value between the target vector and the pre-stored vector. The smaller the similarity value, the less the story tag matches the story. The larger the similarity value, the more the story tag matches the story. Then, select the target story based on the similarity value. The selected target story can be an insurance claim story that is similar to the story tag.
[0087] In one embodiment, the target story includes multiple segments, and step S3, which involves extracting verbs from the target stories and arranging the verbs according to their order in the target stories to obtain a target verb set, includes:
[0088] S301: Extract verbs from multiple target stories and arrange them according to the order of each verb in the corresponding target story to obtain the verb set corresponding to each target story;
[0089] S302: Select one of the verb sets and denote it as the first verb set, and denote the remaining verb sets as the second verb set;
[0090] S303: Randomly select verbs from the second set of verbs and merge them into the first set of verbs to obtain a temporary set of verbs. The merging methods include replacing verbs in the first set of verbs and adding them to the first set of verbs.
[0091] S304: Calculate the reasonableness of the temporary verb set based on the coherence between verbs;
[0092] S305: Determine whether the reasonableness is greater than a preset reasonable threshold;
[0093] S306: If the value is greater than a preset reasonable threshold, then the temporary verb set is recorded as the target verb set.
[0094] As described in steps S301-S302 above, verbs are extracted from multiple target stories and arranged according to the order of each verb in the corresponding target story to obtain a verb set corresponding to each target story; one verb set is selected as the first verb set, and the remaining verb sets are selected as the second verb set; wherein, each target story includes multiple sets of verbs, so a corresponding verb set can be formed, that is, each target story corresponds to a verb set, and then one verb set is selected as the first verb set, and the remaining verb sets are selected as the second verb set. The selection rule can be based on the similarity band, that is, the verb set corresponding to the target story with the highest similarity to the story tag is selected as the first verb set, and the rest are selected as the second verb set.
[0095] As described in steps S303-S304 above, verbs from the second verb set are randomly selected and merged into the first verb set to obtain a temporary verb set. The merging methods include replacing verbs from the first verb set and adding verbs to the first verb set. The reasonableness of the temporary verb set is calculated based on the coherence between the verbs. The coherence between verbs is pre-calculated; here, only the reasonableness needs to be calculated. The reasonableness is obtained by summing and averaging the coherence between adjacent verbs. Randomly selecting verbs from the second verb set and merging them into the first verb set to obtain a temporary verb set, where the merging methods include replacing verbs from the first verb set and adding verbs to the first verb set, essentially adding verbs from the second verb set to the first verb set, thereby enriching the storyline and improving readability for the reader.
[0096] As described in steps S305-S306 above, it is determined whether the reasonableness is greater than a preset reasonable threshold. If it is greater than the preset reasonable threshold, the temporary verb set is recorded as the target verb set. If it is greater than the reasonable threshold, it indicates that the storyline conforms to normal logic; if it is less than the reasonable threshold, it indicates that the storyline does not conform to normal logic, and the verb set needs further adjustment to improve the reasonableness of the claim story and facilitate reading.
[0097] In one embodiment, after step S6, which involves inputting the story encoding and the story tag into a preset decoder to obtain the story text, the method further includes:
[0098] S701: Randomly select a target sentence from the story text, and calculate a first vector by weighting and summing the target vectors corresponding to each sentence from the beginning of the story text to the end of the target sentence; calculate a second vector by weighting and summing the target vectors corresponding to each sentence from the end of the target sentence to the end of the story text; wherein, the dimension of the first vector is equal to the dimension of the second vector;
[0099] S702: Calculate the similarity between the first vector and the second vector corresponding to the target sentence, and then perform a sigmoid non-linear mapping on the calculated first similarity value to the (0,1) interval to find the linear distance with 1;
[0100] S703: Compare the linear distance with a set threshold. When the linear distance is higher than the set threshold, use the end of the target sentence as the paragraph separator.
[0101] S704: Segment the target story based on the paragraph dividing points.
[0102] As described in steps S701-S704 above, the target vectors corresponding to each sentence from the beginning of the story text to the end of the target sentence are weighted and summed to obtain a first vector. The target vectors corresponding to each sentence from the end of the target sentence to the end of the story text are then weighted and summed to obtain a second vector. This weighting and summing includes dimensionality reduction or expansion calculations on the first and second vectors to ensure that the dimensions of the second and first vectors are consistent, facilitating similarity calculation. The similarity calculation formula can be the simhash algorithm, the WMD algorithm (Word Mover's Distance), calculation based on the SVM (Support Vector Machine) vector model, or an algorithm based on cosine similarity, etc., to calculate the similarity between the first and second vectors. Then, the calculated first similarity value is mapped to the (0,1) interval, so that the similarity value is reflected in the linear distance from 1, facilitating subsequent judgment with a threshold. By comparing the similarity value with a set threshold, it can be determined whether the end of each sentence meets the initial conditions for segmentation. When the initial conditions are met, the end position of the corresponding target sentence can be used as the paragraph splitting point. When there are multiple paragraph splitting points, one or more of them can be selected to split the story text into paragraphs.
[0103] In one embodiment, step S6, which inputs the story encoding and the story tag into a preset decoder to obtain the story text, includes:
[0104] S601: The story code is split into multiple codes in sequence;
[0105] S602: The encodings are sequentially input into a preset decoder for decoding; wherein, the current encoding decoding operation is to input the hidden layer from the previous encoding decoding process, the story tag, and the current encoding into the preset decoder to obtain the decoding result of the current encoding;
[0106] S603: Concatenate all the decoding results in order to obtain the target story.
[0107] As described in steps S601-S603 above, during the decoding process, the user's input features are also input as independent input features to the preset decoder. Therefore, the input of the preset decoder when parsing the t-th encoding is:
[0108] 1. Features of the hidden layer state of the previous encoding t-1;
[0109] 2. Word vector features of the output word of the previous encoding t-1;
[0110] 3. User input characteristics (story tags).
[0111] The LSTM pre-defined decoder receives these three inputs at each time step, and the output is the predicted word for the current time step, which also becomes the input for the next time step. Finally, all the generated words are concatenated in order to form a story. The text generation process of this story follows the event flow sequence of the current topic, and each generated word is closely related to the user's input text or image. Because the user's input features are present in each decoding step, it is possible to generate insurance stories, making it easy for people to read a sufficient number of stories related to the original insurance story without barriers, thus improving people's understanding of this type of insurance claim.
[0112] The beneficial effects of this invention are as follows: by acquiring story tags and finding target stories to generate a directed cyclic graph, and using a preset encoding and decoder to generate story text, the generated story text has a similar dramatic plot to the target story, thereby improving the readability of the story text.
[0113] Reference Figure 2 This application also provides a story text generation apparatus, comprising:
[0114] The first acquisition module 10 is used to acquire the story tags of the story to be generated;
[0115] The second acquisition module 20 is used to acquire a target story from a preset story database based on the story tags;
[0116] Extraction module 30 is used to extract verbs from the target story and arrange the verbs according to their order in the target story to obtain a target verb set;
[0117] The construction module 40 is used to construct a directed cyclic graph for all verbs in the target verb set; wherein each node in the directed cyclic graph is composed of a verb;
[0118] The first input module 50 is used to input the directed cyclic graph into a preset encoder to obtain the story code;
[0119] The second input module 60 is used to input the story encoding and the story label into a preset decoder to obtain the story text, wherein the preset encoder and the preset decoder are trained by multiple directed cyclic graphs, the corresponding story labels and the corresponding stories.
[0120] In one embodiment, the first acquisition module 10 includes:
[0121] The `get` submodule is used to retrieve the story image input by the user;
[0122] The extraction submodule is used to extract feature information from the story images according to a preset VIT model;
[0123] A generation submodule is used to generate story tags based on the feature information.
[0124] In one embodiment, the second acquisition module 20 includes:
[0125] The vectorization submodule is used to vectorize the story tags to obtain the multidimensional coordinates X = (x1, x2, x3…x…) of the target vector. n ), where the target vector is the vector corresponding to the story tag;
[0126] The similarity calculation submodule is used to calculate the similarity value based on the formula. Calculate the similarity value between the story tag and the pre-stored vectors of each story in the preset story database, where Y is the multi-dimensional coordinate of each pre-stored vector in the story database, Y = (y1, y2, y3…y…). n );
[0127] A selection submodule is used to select the target story based on the magnitude of the similarity value.
[0128] In a real-time example, the target story includes multiple stories, and the extraction module 30 includes:
[0129] The verb extraction submodule is used to extract verbs from multiple target stories and arrange them according to the order of each verb in the corresponding target story to obtain the verb set corresponding to each target story;
[0130] The selection submodule is used to select one of the verb sets as the first verb set, and the remaining verb sets as the second verb set;
[0131] A random selection submodule is used to randomly select verbs from the second verb set and merge them into the first verb set to obtain a temporary verb set. The merging methods include replacing verbs in the first verb set and adding them to the first verb set.
[0132] The reasonableness calculation submodule is used to calculate the reasonableness of the temporary verb set based on the coherence between verbs;
[0133] The reasonableness judgment submodule is used to determine whether the reasonableness is greater than a preset reasonable threshold.
[0134] This is designated as a submodule, used to designate the temporary verb set as the target verb set if it exceeds a preset reasonable threshold.
[0135] In one embodiment, the story text generation apparatus further includes:
[0136] The random selection module randomly selects a target sentence from the story text, and calculates a first vector by weighting and summing the target vectors corresponding to each sentence from the beginning of the story text to the end of the target sentence, and calculates a second vector by weighting and summing the target vectors corresponding to each sentence from the end of the target sentence to the end of the story text; wherein, the dimension of the first vector is equal to the dimension of the second vector;
[0137] The similarity calculation module is used to calculate the similarity between the first vector and the second vector corresponding to the target sentence, and then perform a sigmoid nonlinear mapping on the calculated first similarity value to the (0,1) interval to find the linear distance with 1.
[0138] The comparison module is used to compare the linear distance with a set threshold. When the linear distance is higher than the set threshold, the end position of the target sentence is used as the paragraph separator.
[0139] The segmentation module is used to segment the target story based on the paragraph dividing points.
[0140] In one embodiment, the second input module 60 includes:
[0141] The splitting submodule is used to split the story code into multiple codes in sequence;
[0142] The input submodule is used to input the encoding sequentially into a preset decoder for decoding; wherein, the current encoding decoding operation is to input the hidden layer from the previous encoding decoding process, the story tag, and the current encoding into the preset decoder to obtain the decoding result of the current encoding;
[0143] The splicing submodule is used to splice all the decoding results in order to obtain the target story.
[0144] Reference Figure 3 This application also provides a computer device, which may be a server, and its internal structure may be as follows: Figure 3As shown. The computer device includes a processor, memory, network interface, and database connected via a system bus. The processor is designed to provide computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and the database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The database is used to store various stories, etc. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it can implement the story text generation method described in any of the above embodiments.
[0145] Those skilled in the art will understand that Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer equipment on which the present application is applied.
[0146] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, can implement the story text generation method described in any of the above embodiments.
[0147] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media provided in this application and in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0148] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0149] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0150] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0151] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of the claims of the present invention.
Claims
1. A method for generating story text, characterized in that, include: Get the story tags for the story to be generated; Retrieve the target story from a preset story database based on the story tags; Extract verbs from the target story, and arrange the verbs according to their order in the target story to obtain the target verb set; Construct a directed cyclic graph for all verbs in the target verb set; wherein each node in the directed cyclic graph consists of a verb. The directed cyclic graph is input into a preset encoder to obtain the story code; The story encoding and the story label are input into a preset decoder to obtain the story text, wherein the preset encoder and the preset decoder are trained using multiple directed cyclic graphs, the corresponding story labels, and the corresponding stories; The target stories include multiple ones. The step of extracting verbs from the target stories and arranging the verbs according to their order in the target stories to obtain a target verb set includes: Extract verbs from multiple target stories and arrange them according to the order of each verb in the corresponding target story to obtain the verb set corresponding to each target story; Select one set of verbs and designate it as the first set of verbs, and designate the remaining sets of verbs as the second set of verbs; the first set of verbs is the set of verbs corresponding to the target story with the highest similarity to the story tag; Verbs from the second set of verbs are randomly selected and merged into the first set of verbs to obtain a temporary set of verbs. The merging methods include replacing verbs from the first set of verbs and adding verbs to the first set of verbs. The reasonableness of the temporary verb set is calculated based on the coherence between verbs; wherein the reasonableness is obtained by summing and averaging the coherence between each adjacent verb. Determine whether the reasonableness is greater than a preset reasonable threshold; If the value exceeds a preset reasonable threshold, the temporary verb set is recorded as the target verb set. After the step of inputting the story encoding and the story tag into a preset decoder to obtain the story text, the method further includes: A target sentence is randomly selected from the story text, and the target vectors corresponding to each sentence from the beginning of the story text to the end of the target sentence are weighted and summed to obtain a first vector. The target vectors corresponding to each sentence from the end of the target sentence to the end of the story text are weighted and summed to obtain a second vector. The dimension of the first vector is equal to the dimension of the second vector. The similarity between the first vector and the second vector corresponding to the target sentence is calculated. The calculated first similarity value is then non-linearly mapped to the (0,1) interval using a sigmoid algorithm to find the linear distance with 1. The linear distance is compared with a set threshold. When the linear distance is higher than the set threshold, the end of the target sentence is taken as the paragraph dividing point. The target story is segmented based on the paragraph dividing points. When multiple paragraph dividing points are included, one or more of the paragraph dividing points are selected to divide the story text into paragraphs.
2. The method for generating story text as described in claim 1, characterized in that, The step of obtaining the story tags for the story to be generated includes: Get the story image input by the user; Feature information is extracted from the story images based on a preset VIT model; Story tags are generated based on the aforementioned feature information.
3. The method for generating story text as described in claim 1, characterized in that, The step of retrieving the target story from a preset story database based on the story tags includes: Vectorize the story tags to obtain the multidimensional coordinates X = (x1, x2, x3…x) of the target vector. n ), where the target vector is the vector corresponding to the story tag; According to the formula Calculate the similarity value between the story tag and the pre-stored vectors of each story in the preset story database, where Y is the multi-dimensional coordinate of each pre-stored vector in the story database. Y = (y1, y2, y3…y n ); The target story is selected based on the magnitude of the similarity value.
4. The method for generating story text as described in claim 1, characterized in that, The step of inputting the story encoding and the story tag into a preset decoder to obtain the story text includes: The story code is split into multiple codes in sequence; The codes are sequentially input into a preset decoder for decoding; wherein, the current encoding decoding operation is to input the hidden layer from the previous encoding decoding process, the story tag, and the current encoding into the preset decoder to obtain the decoding result of the current encoding; By concatenating all the decoding results in order, the target story is obtained.
5. A device for generating story text, characterized in that, include: The first acquisition module is used to acquire the story tags of the story to be generated. The second acquisition module is used to acquire target stories from a preset story database based on the story tags; An extraction module is used to extract verbs from the target story and arrange the verbs according to their order in the target story to obtain a target verb set. A construction module is used to construct a directed cyclic graph for all verbs in the target verb set; wherein each node in the directed cyclic graph is composed of a verb; The first input module is used to input the directed cyclic graph into a preset encoder to obtain the story code; The second input module is used to input the story encoding and the story label into the preset decoder to obtain the story text, wherein the preset encoder and the preset decoder are trained through multiple directed cyclic graphs, the corresponding story labels and the corresponding stories; The target stories include multiple ones, and the extraction module includes: The verb extraction submodule is used to extract verbs from multiple target stories and arrange them according to the order of each verb in the corresponding target story to obtain the verb set corresponding to each target story; The selection submodule is used to select one set of verbs as the first set of verbs, and the remaining sets of verbs as the second set of verbs; the first set of verbs is the set of verbs corresponding to the target story with the highest similarity to the story tag; A random selection submodule is used to randomly select verbs from the second verb set and merge them into the first verb set to obtain a temporary verb set. The merging methods include replacing verbs in the first verb set and adding them to the first verb set. The reasonableness calculation submodule is used to calculate the reasonableness of the temporary verb set based on the coherence between verbs; wherein the reasonableness is obtained by summing and averaging the coherence between each adjacent verb; The reasonableness judgment submodule is used to determine whether the reasonableness is greater than a preset reasonable threshold. This is designated as a submodule, used to designate the temporary verb set as the target verb set if it exceeds a preset reasonable threshold. The random selection module randomly selects a target sentence from the story text, and calculates a first vector by weighting and summing the target vectors corresponding to each sentence from the beginning of the story text to the end of the target sentence, and calculates a second vector by weighting and summing the target vectors corresponding to each sentence from the end of the target sentence to the end of the story text; wherein, the dimension of the first vector is equal to the dimension of the second vector; The similarity calculation module is used to calculate the similarity between the first vector and the second vector corresponding to the target sentence, and then perform a sigmoid nonlinear mapping on the calculated first similarity value to the (0,1) interval to find the linear distance with 1. The comparison module is used to compare the linear distance with a set threshold. When the linear distance is higher than the set threshold, the end position of the target sentence is used as the paragraph separator. The segmentation module is used to segment the target story based on the segmentation points. When multiple segmentation points are included, one or more of the segmentation points are selected to segment the story text into segments.
6. The story text generation apparatus as described in claim 5, characterized in that, The first acquisition module includes: The `get` submodule is used to retrieve the story image input by the user; The extraction submodule is used to extract feature information from the story images according to a preset VIT model; A generation submodule is used to generate story tags based on the feature information.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 4.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.