CN111414736A - Story generation model training method, device, equipment and storage medium - Google Patents

Story generation model training method, device, equipment and storage medium Download PDF

Info

Publication number
CN111414736A
CN111414736A CN202010209921.4A CN202010209921A CN111414736A CN 111414736 A CN111414736 A CN 111414736A CN 202010209921 A CN202010209921 A CN 202010209921A CN 111414736 A CN111414736 A CN 111414736A
Authority
CN
China
Prior art keywords
text
story
generation model
logic
word
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010209921.4A
Other languages
Chinese (zh)
Other versions
CN111414736B (en
Inventor
王伟
李丕绩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202010209921.4A priority Critical patent/CN111414736B/en
Publication of CN111414736A publication Critical patent/CN111414736A/en
Application granted granted Critical
Publication of CN111414736B publication Critical patent/CN111414736B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/35Clustering; Classification

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Machine Translation (AREA)

Abstract

The embodiment of the application discloses a story generation model training method, a story generation model training device, story generation model training equipment and a storage medium, and belongs to the field of natural language processing. The method comprises the following steps: acquiring a first sample prompt text, a first story text and a first logic text corresponding to the first sample prompt text, wherein the first logic text is used for indicating the context logic relationship of the first story text; generating a second story text corresponding to the first sample prompt text based on the story generation model; generating a second logic text corresponding to the second story text based on the logic generation model; and training a story generation model according to the first story text, the second story text, the first logic text and the second logic text. Because the logicality of the generated story is considered in the process of training the story generation model, the accuracy of the story generation model is improved, and the logicality of the story text generated by using the trained story generation model is better.

Description

Story generation model training method, device, equipment and storage medium
Technical Field
The present application relates to the field of natural language processing, and in particular, to a method, an apparatus, a device, and a storage medium for training a story generation model.
Background
With the development of artificial intelligence technology and natural language processing technology, a story text generation method is proposed at present, and the method generates a story text corresponding to a prompt text by acquiring the prompt text input by a user and based on a story generation model, thereby realizing the function of intelligently compiling stories. However, the story generated by adopting the story generation model has the problem of poor logical performance, so how to improve the accuracy of the story generation model becomes a problem which needs to be solved at present.
Disclosure of Invention
The embodiment of the application provides story generation model training, a device, equipment and a storage medium, and can improve the accuracy of story generation models. The technical scheme is as follows:
in one aspect, a story generation model training method is provided, the method comprising:
acquiring a first sample prompt text, a first story text corresponding to the first sample prompt text and a first logic text, wherein the first logic text is used for indicating the context logic relationship of the first story text;
generating a second story text corresponding to the first sample prompt text based on a story generation model;
generating a second logic text corresponding to the second story text based on a logic generation model;
and training the story generation model according to the first story text, the second story text, the first logic text and the second logic text.
Optionally, said adjusting model parameters of said story generation model according to said first loss value and said second loss value comprises:
according to the weight of the second loss value, carrying out weighting processing on the second loss value to obtain a third loss value, wherein the weight is used for indicating the influence degree of the context logic relationship of the story text on the story text;
and adjusting the model parameters of the story generation model according to the first loss value and the third loss value.
Optionally, the obtaining of the first story outline text corresponding to the first sample prompt text includes:
and generating a first story outline text corresponding to the first sample prompt text based on the trained story outline generation model.
Optionally, before generating the first story outline text corresponding to the first sample prompt text based on the trained story outline generation model, the method further includes:
acquiring a second sample prompt text and a second story outline text corresponding to the second sample prompt text;
generating a third story outline text corresponding to the second sample prompt text based on the story outline generation model;
and training the story outline generation model according to the second story outline text and the third story outline text.
Optionally, the logic keywords include: at least one of accept, turn, parallel and time.
In another aspect, a story text generation method is provided, the method including:
and generating a story text corresponding to any prompt text based on a story generation model, wherein the story generation model is obtained by training by adopting the story generation model training method.
In another aspect, there is provided a story generation model training apparatus, the apparatus comprising:
the system comprises an acquisition module, a judgment module and a display module, wherein the acquisition module is used for acquiring a first sample prompt text, a first story text and a first logic text corresponding to the first sample prompt text, and the first logic text is used for indicating the context logic relationship of the first story text;
the story generation module is used for generating a second story text corresponding to the first sample prompt text based on a story generation model;
the logic generation module is used for generating a second logic text corresponding to the second story text based on a logic generation model;
and the training module is used for training the story generation model according to the first story text, the second story text, the first logic text and the second logic text.
Optionally, the training module comprises:
a first determining unit, configured to determine a first loss value between the first story text and the second story text by using a loss function of the story generation model, where the first loss value and an error between the first story text and the second story text are in a positive correlation;
a second determining unit, configured to determine a second loss value between the first logical text and the second logical text by using a loss function of the logical generation model, where the second loss value and an error between the first logical text and the second logical text have a positive correlation;
and the adjusting unit is used for adjusting the model parameters of the story generation model according to the first loss value and the second loss value so as to converge the loss function of the story generation model and the output value of the loss function of the logic generation model.
Optionally, the adjusting unit is further configured to perform weighting processing on the second loss value according to a weight of the second loss value to obtain a third loss value, where the weight is used to indicate an influence degree of a context logical relationship of a story text on the story text;
the adjusting unit is further configured to adjust a model parameter of the story generation model according to the first loss value and the third loss value.
Optionally, the logic generation module is further configured to process at least two adjacent sentences in the second story text based on the logic generation model to obtain logic keywords corresponding to the at least two sentences, where the logic keywords are used to indicate a context logic relationship of the at least two sentences.
Optionally, the logic generation model includes an encoding layer and a text output layer, and the logic generation module includes:
the coding unit is used for acquiring a vector corresponding to each statement in the at least two statements based on the coding layer, and fusing the acquired at least two vectors to obtain a feature vector;
and the text output unit is used for determining the logic key words corresponding to the at least two sentences according to the feature vectors based on the text output layer.
Optionally, the story generation module comprises:
an input unit for inputting the first sample prompt text into the story generation model;
the generating unit is used for generating at least one word corresponding to the first sample prompt text according to the first sample prompt text based on the story generation model;
the generation unit is further configured to continue to generate at least one word according to the first sample prompt text and the generated at least one word based on the story generation model until the number of the generated words reaches a first preset number threshold, so as to obtain a second story text composed of the generated plurality of words.
Optionally, the generating unit is further configured to determine, based on the story generation model, a first attention weight of each of the at least one word according to the first sample prompt text and the at least one word that has been generated;
the generating unit is further configured to continue generating at least one word according to the first sample prompt text, the at least one word and the first attention weight of each word based on the story generation model.
Optionally, the training module is further configured to, if the second story text includes a pronoun, obtain a first attention weight and a preset second attention weight of each word in the second story text before the pronoun;
the training module is further used for training the story generation model according to the first story text, the second story text, the first logic text, the second logic text, the first attention weight of each word and the preset second attention weight of each word.
Optionally, the story generation model includes an attention layer, the training module includes:
a first determining unit, configured to determine a first loss value between the first story text and the second story text by using a loss function of the story generation model, where the first loss value and an error between the first story text and the second story text are in a positive correlation;
a second determining unit, configured to determine a second loss value between the first logical text and the second logical text by using a loss function of the logical generation model, where the second loss value and an error between the first logical text and the second logical text have a positive correlation;
a third determining unit, configured to determine a fourth loss value between the first attention weight and the second attention weight of each word by using the loss function of the attention layer, where the fourth loss value is in a positive correlation with an error between the first attention weight and the second attention weight of the corresponding word;
an adjusting unit, configured to adjust a model parameter of the story generation model according to the first loss value, the second loss value, and the fourth loss value, so that output values of a loss function of the story generation model, a loss function of the logic generation model, and a loss function of the attention layer converge.
Optionally, the story generation module comprises:
the acquisition unit is used for acquiring a first story outline text corresponding to the first sample prompt text;
and the generating unit is used for generating a second story text corresponding to the first sample prompt text and the first story outline text based on the story generating model.
Optionally, the obtaining unit is further configured to generate a first story outline text corresponding to the first sample prompt text based on the trained story outline generation model.
Optionally, the apparatus further comprises:
the obtaining module is further configured to obtain a second sample prompt text and a second story outline text corresponding to the second sample prompt text;
the outline generation module is used for generating a third story outline text corresponding to the second sample prompt text based on the story outline generation model;
the training module is further used for training the story outline generation model according to the second story outline text and the third story outline text.
Optionally, the training module is further configured to train the logic classification model according to the first logic text and the second logic text.
Optionally, the logic keywords include: at least one of accept, turn, parallel and time.
In another aspect, there is provided a story text generating apparatus, the apparatus including:
and the generation module is used for generating a story text corresponding to any prompt text based on a story generation model, and the story generation model is obtained by adopting the device in the aspect.
In yet another aspect, a computer device is provided, which includes a processor and a memory, where the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the operations performed in the story generation model training method according to the above aspect; or, to implement the operations performed in the story text generation method described in the above aspect.
In yet another aspect, a computer-readable storage medium having at least one instruction stored therein, the at least one instruction being loaded and executed by a processor to implement the operations performed in the story generation model training method; or, to implement the operations performed in the story text generation method described in the above aspect.
The beneficial effects brought by the technical scheme provided by the embodiment of the application at least comprise:
according to the story generation model training method, the story generation model training device, the story generation model training equipment and the storage medium, when the story generation model is trained, a second story text output by the story generation model can be used as input of the logic generation model, the logic generation model generates a second logic text corresponding to the second story text, the logic text is used for indicating the context logic relationship of the story text, the story generation model is trained according to the first story text, the second story text, the first logic text and the second logic text, and in the training process, the context logic of the story text is considered, so that the accuracy of the story generation model is improved, and the context logic of the story text generated by the story generation model is improved.
In addition, in the training process, the distribution of the attention weight of each word before the pronouns in the pronouns generation process is also considered, and the accuracy of the story generation model is improved, so that the accuracy of the pronouns is higher in the story text generated based on the trained story generation model, a user can understand stories stated by the story text more easily when reading the story text, and the user experience is improved.
In addition, the method and the device can generate the story outline text corresponding to the prompt text based on the story outline generation model, and then generate the prompt text and the story text corresponding to the story outline text based on the story generation model. Because the story outline text has more contents than the prompt text and is used for indicating the story frame of the story, the story is generated more uniformly in plot and more smoothly in logic if the story outline text is considered in the process of generating the story.
In addition, when the story outline text and the story text are generated, corresponding attention weight is determined for each word in at least one generated word, and the corresponding weight of each word is determined according to the distance between each word and the word to be generated and the matching degree of at least one word and the prompt text, so that the attention point of the model is more accurate, at least one continuously generated word is more accurate, and the continuity of sentences in the generated story text is ensured.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic illustration of an implementation environment provided by an embodiment of the present application;
fig. 2 is a flowchart of a method for generating a story text according to an embodiment of the present application;
FIG. 3 is a flowchart of a method for training a story generation model according to an embodiment of the present application;
FIG. 4 is a flowchart of a method for training a story generation model according to an embodiment of the present application;
FIG. 5 is a flowchart of a method for training a story generation model according to an embodiment of the present application;
FIG. 6 is a flowchart of a method for training a story generation model according to an embodiment of the present application;
FIG. 7 is a schematic structural diagram of a story generation model training apparatus provided in an embodiment of the present application;
FIG. 8 is a schematic structural diagram of another story-generating model training apparatus provided in an embodiment of the present application;
fig. 9 is a schematic structural diagram of a story text generation apparatus provided in an embodiment of the present application;
fig. 10 is a block diagram of a terminal according to an embodiment of the present disclosure;
fig. 11 is a schematic structural diagram of a server according to an embodiment of the present application.
Detailed Description
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
It will be understood that the terms "first," "second," and the like as used herein may be used herein to describe various concepts, which are not limited by these terms unless otherwise specified. These terms are only used to distinguish one concept from another. For example, the first story text may be referred to as second story text, and similarly, the second story text may be referred to as first story text, without departing from the scope of the present application.
As used herein, the terms "at least one," "a plurality," "each," "any," and at least one includes one, two, or more than two, and a plurality includes two or more than two, and each refers to each of the corresponding plurality, and any refers to any one of the plurality, for example, the plurality of words includes 3 words, and each refers to each of the 3 words, and any refers to any one of the 3 words, which may be the first, the second, or the third.
Artificial Intelligence (AI) is a theory, method, technique and application system that uses a digital computer or a machine controlled by a digital computer to simulate, extend and expand human Intelligence, perceive the environment, acquire knowledge and use the knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technique of computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can react in a manner similar to human intelligence. Artificial intelligence is the research of the design principle and the realization method of various intelligent machines, so that the machines have the functions of perception, reasoning and decision making.
The artificial intelligence technology is a comprehensive subject and relates to the field of extensive technology, namely the technology of a hardware level and the technology of a software level. The artificial intelligence infrastructure generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
Natural language processing (Nature L and natural language processing, N L P) is an important direction in the fields of computer science and artificial intelligence, and it is a research on various theories and methods that can realize effective communication between people and computers using natural language.
The scheme provided by the embodiment of the application adopts an artificial intelligence natural language processing technology to generate the story text, and the story generation model training method and the story text generation method are explained in detail through the following embodiments:
the story generation model training method and the story text generation method provided by the embodiment of the application can be applied to computer equipment, and the computer equipment can acquire the first sample prompt text, the first story text corresponding to the first sample prompt text and the first logic text, wherein the first logic text is used for indicating the context logic relationship of the first story text; generating a second story text corresponding to the first sample prompt text based on the story generation model; generating a second logic text corresponding to the second story text based on the logic generation model; training the story generation model according to the first story text, the second story text, the first logic text and the second logic text. The computer device can also generate story text corresponding to any prompt text based on the trained story generation model.
In one possible implementation, the computer device may be a mobile phone, a computer, a tablet computer, or the like. In another possible implementation manner, the computer device may be a server, and the server may be one server, a server cluster composed of several servers, or a cloud computing service center.
In another possible implementation, the computer device may include a terminal and a server. Fig. 1 is a schematic diagram of an implementation environment provided in an embodiment of the present application, and referring to fig. 1, the implementation environment includes: a terminal 101 and a server 102, wherein the terminal 101 and the server 102 are connected in a communication way.
Optionally, the terminal 101 may upload the first sample prompt text, the first story text corresponding to the first sample prompt text, and the first logic text to the server; the server 102 generates a second story text corresponding to the first sample prompt text based on the story generation model, generates a second logic text corresponding to the second story text based on the logic generation model, and trains the story generation model according to the first story text, the second story text, the first logic text and the second logic text. After training the story generation model, the terminal 101 may also upload any prompt text to the server 102, and the server 102 generates a story text corresponding to any prompt text based on the trained story generation model.
Alternatively, the terminal 101 may have a target application installed thereon, and the target application may be an application having a language processing function or an application related to language processing. The server 102 may be a server that provides services for the target application.
The method provided by the embodiment of the application can be applied to a language processing scene.
For example: in a scene for assisting a user in writing, the user wants to write a story about 'biography of a character', the user can input a prompt text related to the 'biography of the character' in computer equipment, and the computer equipment can train a story generation model and generate a story text related to the 'biography of the character' based on the trained story generation model by adopting the method provided by the embodiment of the application after acquiring the prompt text, so that the user can modify the story text to obtain the story text wanted by the user, and the effect of assisting the user in writing is realized.
Because the story generation model considers the logicality of the generated story text in the training process, when the story text is generated by using the trained story generation model, the generated story text has better logicality and smoother chapter relationship, thereby better meeting the requirements of users and improving the auxiliary effect.
Besides the above scenarios, the method provided in the embodiment of the present application may also be applied to other scenarios such as generating news, which is not limited in the embodiment of the present application.
Fig. 2 is a flowchart of a story text generation method provided in an embodiment of the present application. The execution subject of the embodiment of the application is computer equipment, and referring to fig. 2, the method includes:
201. and acquiring a prompt text, and inputting the prompt text into the story outline generation model.
The prompt text can comprise at least one word, the prompt text is input into a story outline generation model, and the story outline generation model can be expanded based on the at least one word in the prompt text to generate more words and obtain a story outline text.
The prompt text can be any part of the story and used for indicating part of information of the story, optionally, the prompt text can be used for indicating a theme of the story outline generated by the story outline generation model, and different prompt texts are input into the story outline generation model, so that the story outline generation model can generate story outlines with different themes. For example, the prompt text is "compose a story of a character biography", and the prompt text is used to indicate that the subject of the story outline is "character biography".
Alternatively, the prompt text may be the subject text of the story. For example, the prompt text is "character biography". Alternatively, the prompt text may be the first sentence at the beginning of the story. For example, the prompt text is "live a long time ago, a good life on a mountain". The prompt text can be other, and only at least one word is required to be included in the prompt text.
The prompt text can be a text input by a user, and therefore, acquiring the prompt text comprises acquiring the text input by the user; the prompt text may also be text that is automatically obtained by the computer device. For example, in the process of composing a novel, after the user closes the composition page each time, the computer device may acquire a story that the user has composed, use the last sentence of the story as a prompt text, and input the prompt text into the story outline generation model to generate a story outline text of a subsequent story, so that the user may continue composing the story with reference to the story outline text generated by the story outline generation model.
202. And generating a story outline text corresponding to the prompt text based on the story outline generation model.
The story outline generation model is a model for generating a story outline text, and may generate a story outline text related to at least one word according to the at least one word input, and optionally, the story outline generation model may be an RNN (Recurrent Neural Network) model, an L STM (L one short-Term Memory) model, a fully connected Neural Network model, or the like.
The story outline text may be used to indicate a story frame of a story, for example, to indicate an event occurring in the story, or to indicate a trend of the event in the story, and the like. Alternatively, the story outline text may be abstract text of the story, chapter directory text of the story, or the like. The embodiment of the application does not limit the content included in the text of the story outline.
The story outline text corresponding to the prompt text is the story outline text generated based on the prompt text, and optionally, some information in the story outline text is consistent with information in the prompt text. For example, if the prompt text is used to indicate a subject of a story, the subject of the story outline text corresponding to the prompt text is the same as the subject indicated by the prompt text; if the prompt text is used for indicating the event in the story, the event in the story outline text corresponding to the prompt text is consistent with the event indicated in the prompt text; and if the prompt text is used for indicating the character in the story, the character in the story outline text corresponding to the prompt text is consistent with the character indicated in the prompt text, and the like.
Optionally, in the process of generating the story outline text based on the story outline generation model, the terms may be generated one by one based on the story outline generation model, so as to obtain the story outline text composed of a plurality of terms. In one possible implementation manner, generating the story outline text corresponding to the prompt text based on the story outline generation model may include: generating at least one word according to the prompt text based on the story outline generation model; and based on the story outline generation model, continuously generating at least one word according to the prompt text and the generated at least one word to obtain a story outline text consisting of a plurality of words. Alternatively, the order of arrangement of the plurality of words in the story outline text may be the order of generation of the plurality of words.
Optionally, when the story outline text generates at least one word, at least one word may be selected from the plurality of candidate words according to the prompt text. Optionally, a plurality of words may be set in the story outline generation model, when at least one word is generated based on the story outline generation model, the probability of each word in the plurality of words may be obtained according to the prompt text and the generated at least one word, and the word with the highest probability is used as the next word to be generated, and so on, thereby generating the story outline text including the plurality of words.
For example, 2 ten thousand words are set in the story outline generation model, the prompt text is "fairy tale", at least one word that has been generated is "a public in castle", and based on the story outline generation model, the probability of each word in the 2 ten thousand words is obtained according to the prompt text and the at least one word that has been generated, wherein the probability of "main" is the highest, and therefore "main" is taken as the next word that is continuously generated.
Optionally, when the at least one word is continuously generated according to the prompt text and the generated at least one word based on the story outline generation model, different attention weights may be determined for each word in the at least one word, so that the attention weight of a part of the at least one word is higher, the attention weight of a part of the word is lower, and the attention weight of the part of the word is highly concerned, wherein the part of the word which is highly concerned may be a word which is closely related to the word to be generated, a word which is closely related to an event occurring in the story, and the like, so that the continuously generated at least one word is more accurate, and the continuity of the generated sentences is ensured.
In one possible implementation, generating a model based on the story outline, and continuing to generate at least one word according to the prompt text and the at least one word that has been generated may include: determining an attention weight of each word in the at least one word according to the prompt text and the generated at least one word based on the story generation model; and based on the story generation model, continuing to generate at least one word according to the prompt text, the at least one word and the attention weight of each word.
Optionally, when determining the attention weight of each of the at least one word according to the prompt text and the generated at least one word, the attention weight of each of the at least one word may be determined according to a distance between each of the at least one word and a word to be generated and a matching degree between each of the at least one word and the prompt text. Optionally, the closer each of the at least one word is to the word to be generated, the higher the attention weight of the word is, and the higher the matching degree of each of the at least one word with the prompt text is, the higher the attention weight of the word is.
For example, the prompt text is "fairy tale", at least one word that has been generated is "a public in castle", wherein the distance between "public" and the word to be generated is the closest, and the matching degree of "public" and "fairy tale" is the highest, the attention weight of "public" is determined to be 0.8, the attention weight of "yes" is determined to be 0.12, and the attention weight of "i" is determined to be 0.08.
It should be noted that, in the embodiment of the present application, the process of generating the story outline text corresponding to the cue text based on the story outline generation model is described by merely determining the attention weight of each word in the at least one word according to the cue text and the at least one word that has been generated, and continuing to generate the at least one word according to the cue text, the at least one word and the attention weight of each word.
In another embodiment, the probability of each of the plurality of words set in the story outline generation model can be determined according to the distance between each of the at least one generated word and the word to be generated based on the story outline generation model, the probability of each of the plurality of words is adjusted according to the prompt text, and the word with the highest probability is used as the next generated word according to the adjusted probability of each word. The embodiment of the present application does not limit the process of continuing to generate at least one word according to the prompt text and the at least one word that has been generated.
In addition, when a story outline text corresponding to the prompt text is generated based on the story outline generation model, a preset condition may be set, when the preset condition is satisfied, the continuous generation of at least one word is stopped, and the story outline text composed of the generated at least one word is output. Alternatively, the preset condition may indicate the number of words, for example, when the number of generated words reaches a second preset number threshold value based on the story outline generation model, a story outline text composed of a plurality of words is obtained. Wherein the second preset number threshold is any integer greater than 1, for example: 50. 100, 150, etc.
For example, the second preset number threshold is 100, the prompt text includes 10 words, the expansion processing is performed on the prompt text based on the story outline generation model, when 100 words are obtained, the generation of the next word is terminated, the 100 words are output, and the text formed by the 100 words is the story outline text.
Optionally, the preset condition may further indicate the number of sentences, for example, when the number of generated sentences reaches a third preset number threshold value based on the story outline generation model, a story outline text composed of a plurality of sentences is obtained. Wherein the third preset number threshold is any integer greater than 1, for example: 3. 4, 5, 6, etc.
For example, when the third preset number threshold is 5, the sentence of the presentation text is 1, and the presentation text is expanded based on the story outline generation model to obtain 5 sentences, the generation of the word of the next sentence is terminated, and the 5 sentences are output, and the text formed by the 5 sentences is the story outline text. Preset separators can be arranged between the sentences, and when the preset separators are detected, a complete sentence is determined to be generated. The preset delimiter may be at least one of a period, a semicolon, an exclamation point, a question mark, etc.
Optionally, in the process of generating the story outline text corresponding to the prompt text based on the story outline generation model, a word vector of a word in the prompt text may be processed. For example, after the prompt text is input into the story outline generation model, the story outline generation model performs word segmentation on the prompt text to obtain a plurality of words, obtains a word vector of each word in the plurality of words according to the plurality of words, and generates at least one word according to the word vector of each word in the plurality of words.
Optionally, obtaining a word vector of each word in the plurality of words according to the plurality of words may include: obtaining a word vector corresponding to each word in the plurality of words according to the word vector dictionary; or, each word in the plurality of words is encoded by the encoder to obtain a word vector of each word.
203. And inputting the prompt text and the story outline text into a story generation model.
The story generation model is used for generating a story text, the prompt text and the story outline text corresponding to the prompt text are input into the story generation model, and the story generation model can generate the story text matched with the content indicated by the prompt text and the content indicated by the story outline text.
Optionally, the story generation model may be an RNN model, an L STM model, a fully connected neural network model, or the like, and the story generation model is not limited in the embodiments of the present application.
When the prompt text and the story outline text are input to the story generation model, the story generation model is required to identify which text is the prompt text and which text is the story outline text, so that the story generation model generates the story text with reference to the prompt text and the story outline text. Optionally, inputting the prompt text and the story outline text into the story generation model may include: firstly, inputting a prompt text into a story generation model, and then inputting a story outline text into the story generation model; or, the story outline text is input into the story generation model, and then the prompt text is input into the story generation model; or, the prompt text and the story outline text are connected by the aid of the separators, and the connected text is input into the story generation model, so that the story generation model can be determined according to the separators, the text in front of the separators is the prompt text, and the text behind the separators is the story outline text. The segmenter may be [ SEP ], [ S ], or the like, and the embodiment of the present application does not limit the segmenter.
204. And generating a story text corresponding to the prompt text and the story outline text based on the story generation model.
The story text is text for describing a story, and the story text may include a plurality of sentences through which the story is formulated.
The story text corresponding to the prompt text and the story outline text refers to the story text generated by the story generation model according to the prompt text and the story outline text. Optionally, some of the information in the story text may be consistent with the information in the cue text and story outline text. For example, if the story theme indicated by the prompt text is "character biography," and the story outline text indicates an event occurring on the character, the story text indicates the story of the character, and the events occurring in the story are the same as the events indicated by the story outline text.
The relationship among the prompt text, the story outline text and the story text can be regarded as: the story outline text is an extension of the prompt text, the story outline text includes more information than the prompt text, the story text is an extension of the story outline text, and the story text includes more information than the story outline text. For example, the prompt text is composed of 1 sentence, the story outline text is composed of 5 sentences, and the story text is composed of 10 sentences.
Alternatively, in the process of generating the story text based on the story generation model, words may be generated one by one based on the story generation model, resulting in the story text composed of a plurality of words. In one possible implementation, generating the story text corresponding to the prompt text and the story outline text based on the story generation model may include: generating at least one word according to the prompt text and the story outline text based on a story generation model; and based on the story generation model, continuously generating at least one word according to the prompt text, the story outline text and the generated at least one word to obtain a story text consisting of a plurality of words. Alternatively, the order of arrangement of the plurality of words in the story text may be the order of generation of the plurality of words.
Optionally, a plurality of words may be set in the story generation model, and when at least one word is generated based on the story generation model, the probability of each word in the plurality of words may be obtained according to the prompt text, the story outline text, and the at least one word that has been generated, and the word with the highest probability is used as the next word to be generated.
Optionally, when at least one word is continuously generated according to the prompt text, the story outline text and the generated at least one word based on the story generation model, different attention weights may be determined for each word in the at least one word, so that the attention weight of a part of the at least one word is higher, the attention weight of the part of the word is lower, and the attention weight of the part of the word is highly concerned, wherein the part of the word which is highly concerned may be a word which is closely related to the word to be generated, a word which is closely related to an event occurring in the story, and the like, so that the continuously generated at least one word is more accurate, and the continuity of the generated sentences is ensured. In one possible implementation, based on the story generation model, continuing to generate at least one word from the prompt text, the story outline text, and the at least one word that has been generated may include: determining attention weight of each word in at least one word according to the prompt text, the story outline text and the generated at least one word based on the story generation model; and based on the story generation model, continuously generating at least one word according to the prompt text, the story outline text, the at least one word and the attention weight of each word.
Optionally, when determining the attention weight of each of the at least one word according to the cue text, the story outline text and the at least one word that has been generated, the attention weight of each of the at least one word may be determined according to a distance between each of the at least one word and a word to be generated, a matching degree between each of the at least one word and the cue text, and a matching degree between each of the at least one word and the story outline text. Optionally, the closer each of the at least one word is to the word to be generated, the higher the attention weight of the word is, the higher the matching degree of each of the at least one word with the cue text is, the higher the attention weight of the word is, and the higher the matching degree of each of the at least one word with the story outline text is, the higher the attention weight of the word is.
It should be noted that, in the embodiments of the present application, the process of generating the story text corresponding to the cue text and the story outline text based on the story generation model is described only by taking an example of determining the attention weight of each word in the at least one word according to the cue text, the story outline text and the at least one word that have been generated, and continuing to generate the at least one word according to the cue text, the at least one word and the attention weight of each word.
In another embodiment, the probability of each of the plurality of words set in the story generation model is determined according to the distance between each of the at least one generated word and the word to be generated based on the story generation model, the probability of each of the plurality of words is adjusted according to the prompt text and the story outline text, and the word with the highest probability is used as the next generated word according to the adjusted probability of each word. The embodiment of the present application does not limit the process of continuing to generate at least one word according to the prompt text and the at least one word that has been generated.
In addition, based on the story generation model, when the story text corresponding to the prompt text and the story outline text is generated, a preset condition can be set, and when the preset condition is met, at least one word is stopped from being continuously generated to obtain the story text. Alternatively, the preset condition may indicate a number of words, for example, when the number of generated words reaches a first preset number threshold based on the story generation model, a story text composed of a plurality of words is obtained. Wherein, the first preset number threshold is any integer greater than 1, for example: 300. 500, etc.
Optionally, the preset condition may further indicate the number of sentences, for example, when the number of generated sentences reaches a fourth preset number threshold value based on the story generation model, a story text composed of a plurality of sentences is obtained. Wherein the fourth preset number threshold is any integer greater than 1, for example: 10. 15, etc.
Optionally, in the process of generating the story text corresponding to the prompt text and the story outline text based on the story generation model, word vectors of words in the prompt text and the story outline text may be processed. For example, after the prompt text and the story outline text are input into the story generation model, the story generation model performs word segmentation processing on the prompt text and the story outline text to obtain a plurality of words, and a word vector of each word in the plurality of words is obtained according to the plurality of words.
Optionally, obtaining a word vector of each word in the plurality of words according to the plurality of words may include: obtaining a word vector corresponding to each word in the plurality of words according to the word vector dictionary; or, each word in the plurality of words is encoded by the encoder to obtain a word vector of each word.
In addition, the other contents of step 204 are similar to step 202, and refer to step 202, which is not described herein again.
It should be noted that, in the embodiment of the present application, the generation method of the story text is described only by taking the example of generating the story text through the story outline generation model and the story generation model, and in another embodiment, the above steps 201 to 204 may be completed through the story generation model. In one possible implementation mode, a prompt text is obtained, the prompt text is input into a story generation model, and a story outline text corresponding to the prompt text is generated based on the story generation model; and generating a corresponding story text according to the prompt text and the story outline text.
Optionally, in the process of generating the story text according to the prompt text, the story outline text may be generated or not. In one possible implementation mode, the prompt text is input into the story generation model, and the story text corresponding to the prompt text is directly generated based on the story generation model.
Due to the fact that the story text has more contents, in the related technology, the problem that the story plots are inconsistent before and after the story text is generated may occur in the process of generating the story text, if the story text generation method provided by the embodiment of the application is adopted, the story outline text corresponding to the prompt text can be generated based on the story outline generation model, and then the story text corresponding to the prompt text and the story outline text is generated based on the story generation model. Because the story outline text has more contents than the prompt text and is used for indicating the story frame of the story, the story is generated more uniformly in plot and more smoothly in logic if the story outline text is considered in the process of generating the story.
In addition, when the story outline text and the story text are generated, corresponding attention weight is determined for each word in at least one generated word, and the corresponding weight of each word is determined according to the distance between each word and the word to be generated and the matching degree of at least one word and the prompt text, so that the attention point of the model is more accurate, at least one word continuously generated is more accurate, and the continuity of the generated sentences is ensured.
It should be noted that before the story outline generation model and the story generation model are used, the story outline generation model and the story generation model need to be trained. Because the training method of the story outline generation model is similar to the training method of the story generation model, the following embodiments only take the training method of the story generation model as an example for explanation, and the training method of the story outline generation model can refer to the training method of the story generation model, which is not described in detail herein.
Fig. 3 is a flowchart of a story generation model training method provided in an embodiment of the present application. The execution subject of the embodiment of the application is computer equipment, and referring to fig. 3, the method includes:
301. and acquiring a first sample prompt text, a first story text and a first logic text corresponding to the first sample prompt text.
The first sample prompt text, the first story text corresponding to the first sample prompt text and the first logic text are training data for training a story generation model. The first sample prompt text can include at least one word, and the first story text corresponding to the first sample prompt text can include a plurality of sentences. Optionally, the subject matter of the story in the first story text is the same as the subject matter indicated by the first sample prompt text.
The first logic text is used for indicating the context logic relationship of the first story text, wherein the context logic relationship of the story text can be the logic relationship of at least two adjacent sentences in the story text; the logical relationship between at least two adjacent paragraphs in the story text is also possible, and the context scope is not limited in the embodiments of the present application. The first logical text may include at least one logical keyword therein. In one possible implementation, the logical keywords include: at least one of accept, turn, parallel and time.
Wherein the first logical text includes a context logical relationship of the first story text, optionally, obtaining the first logical text may include: and obtaining conjunctions in the first story text, and determining the conjunctions in the first story text as the context logic relationship of the first story text. For example, the conjunction "and" or "corresponds to the logical keyword" in parallel ", the conjunction" but "corresponds to the logical keyword" in turn ", and so on.
For example, a story is obtained, the title of the story is written into a sample prompt text, the story is written into a story text corresponding to the sample prompt text, and a logic keyword corresponding to a conjunction in the story is written into a first logic text.
302. And generating second story text corresponding to the first sample prompt text based on the story generation model.
After the first sample prompt text and the first story text corresponding to the first sample prompt text are obtained, the first sample prompt text and the first story text can be input into a story generation model, and a second story text corresponding to the first sample prompt text is generated based on the story generation model.
Alternatively, the first sample prompt text and the first story text may be connected using a separator when the first sample prompt text and the first story text are input to the story generation model, and the story generation model may determine that a text located before the separator is the first sample prompt text and a text located after the separator is the first story text when the separator is detected.
In one possible implementation, generating a second story text corresponding to the first sample prompt text based on the story generation model may include: inputting the first sample prompt text into the story generation model; generating at least one word corresponding to the first sample prompt text according to the first sample prompt text based on the story generation model; and based on the story generation model, continuing to generate at least one word according to the first sample prompt text and the generated at least one word until the number of the generated words reaches a first preset number threshold value, and obtaining a second story text formed by the generated words.
Optionally, based on the story generation model, continuing to generate at least one word from the first sample prompt text and the at least one word that has been generated may include: determining a first attention weight for each of the at least one word from the first sample prompt text and the at least one word that has been generated based on the story generation model; based on the story generation model, continuing to generate at least one word according to the first sample prompt text, the at least one word, and the first attention weight for each word.
In one possible implementation, generating a second story text corresponding to the first sample prompt text based on the story generation model may include: acquiring a first story outline text corresponding to the first sample prompt text; and generating second story text corresponding to the first sample prompt text and the first story outline text based on the story generation model.
Optionally, the obtaining of the first story outline text corresponding to the first sample prompt text includes: and generating a first story outline text corresponding to the first sample prompt text based on the trained story outline generation model.
It should be noted that step 302 is similar to step 202 and step 204, and reference may be made to step 202 and step 204, which is not described in detail herein.
Optionally, before generating the first story outline text corresponding to the first sample prompt text based on the trained story outline generation model, the method further includes: acquiring a second sample prompt text and a second story outline text corresponding to the second sample prompt text; generating a third story outline text corresponding to the second sample prompt text based on the story outline generation model; and training the story outline generation model according to the second story outline text and the third story outline text.
Optionally, the story outline text may be an abstract text of the story text, and obtaining the second sample prompt text and the second story outline text corresponding to the second sample prompt text may include: obtaining a subject text of any story text, and taking the prompt text as a second sample prompt text; and processing any story text through an abstract acquisition tool to obtain an abstract text of any story text, and taking the abstract text as a second story outline text.
It should be noted that the process of training the story outline generation model is similar to the process of training the story text generation model in the embodiment of the present application, and details are not repeated here.
303. And generating a second logic text corresponding to the second story text based on the logic generation model.
After generating a second story text corresponding to the first sample prompt text based on the story generation model, the second story text and the first logical text may be input into the logical generation model.
The logic generation model may be a model for determining a context logic relationship, and optionally, the logic generation model may be a classification model, for example, a plurality of logic keywords are set in the logic generation model, each logic keyword indicates a logic relationship, and after the story text is input to the logic generation model, the logic generation model may determine which logic relationship the context logic relationship in the story text is, so as to output the corresponding logic keyword.
Optionally, the context in the story text may be at least two adjacent sentences in the story text, or at least two adjacent paragraphs in the story text, and the context may be set according to different requirements. In the present embodiment, when the context is at least two adjacent sentences or at least two adjacent paragraphs, the manner of determining the context logical relationship based on the logic generation model is similar, and the at least two adjacent sentences are only exemplified in the context in the present embodiment.
If the context is at least two adjacent sentences, in one possible implementation, generating a second logical text corresponding to the second story text based on the logical generation model may include: and processing at least two adjacent sentences in the second story text based on the logic generation model to obtain logic keywords corresponding to the at least two sentences, wherein the logic keywords are used for indicating the context logic relationship of the at least two sentences. And generating a second logic text corresponding to the second story text by acquiring logic keywords corresponding to each adjacent at least two sentences in the second story text, wherein the second logic text comprises the logic keywords corresponding to each adjacent at least two sentences in the second story text.
Optionally, based on the logic generation model, when at least two adjacent sentences in the second story text are processed to obtain logic keywords corresponding to the at least two sentences, a vector corresponding to each sentence in the at least two sentences may be obtained, and the logic relationship between the at least two sentences is determined according to the at least two vectors. Optionally, when obtaining the vector corresponding to the sentence, the sentence may be subjected to word segmentation to obtain a plurality of words, obtain vectors corresponding to the plurality of words, and perform maximum value processing on the plurality of vectors to obtain a vector corresponding to the sentence.
In one possible implementation, the vector corresponding to the statement and the vectors corresponding to the plurality of words of the statement may satisfy the following relationship:
Figure BDA0002422466800000201
Figure BDA0002422466800000202
among them, encoder (S)i) For the ith statement SiA plurality of words in (a) are encoded,
Figure BDA0002422466800000203
is a sentence SiA vector matrix corresponding to a plurality of words in (b), max is a function taking the maximum value,
Figure BDA0002422466800000204
is the maximum value in each column of the orientation quantity matrix,
Figure BDA0002422466800000205
is a vector corresponding to the statement, wherein i is any integer greater than or equal to 1.
For example, each word corresponds to a vector of 100 dimensions, statement SiIncluding the inclusion of 10 words or phrases,
Figure BDA0002422466800000206
the vector matrix is 10 x 100, the maximum value of each column in the vector matrix is obtained, and a sentence S of 1 x 100 is obtainediA corresponding vector matrix indicating a vector as a 100-dimensional vector.
Wherein the logical generative model may include multiple layers, with different layers for different processing of the entered story text. Optionally, the logic generation model may include an encoding layer and a text output layer, where the encoding layer is configured to obtain a vector corresponding to a sentence in the story text, and the text output layer is configured to obtain a context logic relationship of the story text according to the vector corresponding to each sentence in the story text, and output a corresponding logic keyword. Optionally, the coding layer may adopt an encoder structure, and implement coding of words or statements according to the encoder; the text output layer may include a feed-forward neural network by which one or more logical keywords may be selected from a plurality of logical keywords as contextual logical relationships of the story text.
In a possible implementation manner, processing at least two adjacent sentences in the second story text based on the logic generation model to obtain logic keywords corresponding to the at least two sentences may include: acquiring a vector corresponding to each statement in the at least two statements based on the coding layer, and performing fusion processing on the acquired at least two vectors to obtain a feature vector; and determining logic keywords corresponding to the at least two sentences according to the feature vector based on the text output layer.
Optionally, the text output layer may be provided with a plurality of logic keywords, and the text output layer may determine the probability of each logic keyword according to at least two adjacent sentences, and output the logic keyword with the highest probability as the logic relationship between the at least two adjacent sentences. For example, based on the text output layer, the probability of each logical keyword is determined according to the feature vector, and the logical keyword with the highest probability is output.
In one possible implementation, the probabilities of the vectors, feature vectors, and logical keywords corresponding to the sentences may satisfy the following relationships:
Figure BDA0002422466800000211
P(dis|Si,Si+1)=softmax(W0f+b0);
wherein f is a vector
Figure BDA0002422466800000212
Sum vector
Figure BDA0002422466800000213
The feature vector after the fusion processing, tanh is the fusion function, WfAnd bfFor the model parameters of the coding layer, P is the probability, dis is any logical key, P (dis | S)i,Si+1) Is a sentence SiAnd sentence Si+1Probability of any logical keyword, softmax is a classification function, W0And b0Model parameters for the text output layer.
For example, as shown in fig. 4, the second story text 401 is input to the logic generation model 402, the sentence S1 and the sentence S2 in the second story text are processed based on the coding layer 4021 to obtain vectors corresponding to the sentence S1 and the sentence S2, the two vectors are fused to obtain feature vectors of the sentence S1 and the sentence S2, the feature vectors are input to the text output layer 4022, the text output layer 4022 determines the probability of each logical keyword corresponding to the sentence S1 and the sentence S2 based on the feature vectors, and the logical keyword having the highest probability is output.
304. Training the story generation model according to the first story text, the second story text, the first logic text and the second logic text.
And the error between the first story text and the second story text is used for indicating the accuracy of the story generated by the story generation model, and the smaller the error is, the higher the accuracy of the generated story text is. An error between the first logical text and the second logical text indicates a contextual logical fluency of the story text generated by the story generation model, the smaller the error, the more fluent the contextual logical of the story text.
Alternatively, when training the story generation model based on the first story text, the second story text, the first logic text, and the second logic text, an error between the first story text and the second story text may be determined based on the story generation model, an error between the first logic text and the second logic text may be determined based on the logic generation model, and the story generation model may be trained based on the two obtained errors.
In one possible implementation, training the story generation model based on the first story text, the second story text, the first logic text, and the second logic text may include: determining a first loss value between the first story text and the second story text by adopting a loss function of the story generation model, wherein the first loss value and an error between the first story text and the second story text are in a positive correlation relationship; determining a second loss value between the first logic text and the second logic text by adopting a loss function of the logic generation model, wherein the second loss value and the error between the first logic text and the second logic text are in positive correlation; and adjusting the model parameters of the story generation model according to the first loss value and the second loss value so as to converge the output values of the loss function of the story generation model and the loss function of the logic generation model.
In one possible implementation, the loss function of the story generation model may use the following formula:
Figure BDA0002422466800000221
wherein, L1Is a first loss value, T is the number of words included in the story text, T is the serial number of the words, and is changed from 1 to T, xtIs the vector of the t-th word, x≤t-1For the set of vectors for each word before the t-th word, logp (x)t|x≤t-1) The set of vectors for the first t words is x≤t-1The probability corresponding to the tth word.
In one possible implementation, the loss function of the logic generation model may use the following formula:
Figure BDA0002422466800000222
wherein, L2In order to be the second loss value,
Figure BDA0002422466800000223
for the logical keywords in the second logical text, p (dis) is the probability for each keyword determined by the logical generative model.
For example, if the influence of the first loss value on the story generation model and the influence of the second loss value on the story generation model are the same when adjusting the model parameters of the story generation model, the sum of the first loss value and the second loss value may be obtained, and the model parameters of the story generation model may be adjusted according to the sum of the first loss value and the second loss value, for example, L-L11L2Wherein L is the sum of the first loss value and the third loss value, L1Is the first loss value, L2Is the second loss value, λ1The weight corresponding to the second loss value.
For another example, the first loss value has a large influence on the story generation model, the second loss value has a small influence on the story generation model, and the second loss value can be weighted according to the weight of the second loss value to obtain a third loss value, where the weight is used to indicate the influence degree of the context logic relationship of the story text on the story text; and adjusting the model parameters of the story generation model according to the first loss value and the third loss value. Optionally, adjusting model parameters of the story generation model according to the first loss value and the third loss value may include: and acquiring the sum of the first loss value and the third loss value, and adjusting the model parameters of the story generation model according to the sum.
It should be noted that the logic generation model adopted in the embodiment of the present application may be an untrained logic generation model, or may be a trained logic generation model. If the logic generating model is an untrained model, in a possible implementation, after generating a second logic text corresponding to the second story text based on the logic generating model, the method further includes: and training the logic classification model according to the first logic text and the second logic text. The training process of the logic generation model is similar to that of the story generation model, and is not repeated here.
According to the story generation model training method provided by the embodiment of the application, when the story generation model is trained, a second story text output by the story generation model can be used as the input of the logic generation model, the logic generation model generates a second logic text corresponding to the second story text, wherein the logic text is used for indicating the context logic relationship of the story text, the story generation model is trained according to the first story text, the second story text, the first logic text and the second logic text, and in the training process, the context logic of the story text is considered, so that the accuracy of the story generation model is improved, and the context logic of the story text generated by the story generation model is improved.
It should be noted that before the story outline generation model and the story generation model are used, the story outline generation model and the story generation model need to be trained. Because the training method of the story outline generation model is similar to the training method of the story generation model, the following embodiments only take the training method of the story generation model as an example for explanation, and the training method of the story outline generation model can refer to the training method of the story generation model, which is not described in detail herein.
Fig. 5 is a flowchart of a story generation model training method provided in an embodiment of the present application. The execution subject of the embodiment of the application is computer equipment, and referring to fig. 5, the method includes:
501. and acquiring a first sample prompt text and a first story text corresponding to the first sample prompt text.
Step 501 is similar to step 301, and reference may be made to step 301, which is not described in detail herein.
502. And based on the story generation model, continuously generating at least one word according to the first sample prompt text, the generated at least one word and the first attention weight of each word in the at least one word to obtain a second story text containing a plurality of words.
Step 502 is similar to step 202, step 204 and step 302, and reference may be made to step 202, step 204 and step 302, which is not described in detail herein.
In one possible implementation, before the story-based generation model continues to generate at least one word according to the first sample prompt text, the at least one word that has been generated, and the first attention weight corresponding to each of the at least one word, and a second story text containing a plurality of words is obtained, the method further includes: inputting the first sample prompt text into the story generation model; and generating at least one word corresponding to the first sample prompt text according to the first sample prompt text based on the story generation model.
In one possible implementation, the story generation model based on continuing to generate at least one word according to the first sample prompt text, the at least one word that has been generated, and the first attention weight corresponding to each word in the at least one word, and obtaining a second story text containing a plurality of words may include: determining a first attention weight for each of the at least one word from the first sample prompt text and the at least one word that has been generated based on the story generation model; and based on the story generation model, continuously generating at least one word according to the first sample prompt text, the at least one word and the first attention weight of each word to obtain a second story text containing a plurality of words.
In one possible implementation, the story generation model based on continuing to generate at least one word according to the first sample prompt text, the at least one word that has been generated, and the first attention weight corresponding to each word in the at least one word, and obtaining a second story text containing a plurality of words may include: and based on the story generation model, continuing to generate at least one word according to the first sample prompt text, the at least one word and the first attention weight of each word in the at least one word until the number of the generated words reaches a first preset number threshold value, and obtaining a second story text containing a plurality of words.
503. And if the pronouns are included in the second story text, acquiring a first attention weight and a preset second attention weight of each word before the pronouns in the second story text.
Wherein, pronouns can include: "he," "she," "it," "his," and the like, pronouns may be used to refer to a person, to an occurrence, and the like.
Currently, in the related art, pronouns in story texts generated based on story generation models are referred to as errors. For example, "Xiaoming goes to sleep ten o 'clock in the evening, and she gets up five o' clock in the morning today," Xiaoming "and" she "refer to the same character, but" Xiaoming "refers to a boy and" she "refers to a girl, and thus a problem of referring to mistakes occurs.
If in the process of generating the 'Xiaoming night ten times to sleep and then she gets up five times in the morning's, the next generated word is determined to be 'her' according to the attention weight of each word in the first sample prompt text, 'Xiaoming night ten times to sleep, today morning' and 'Xiaoming night ten times to sleep and today morning', because the 'Xiaoming' is far away from the word to be generated, the attention weight of the 'Xiaoming' is low, and the generated 'her' is wrong.
Therefore, after the second story text is generated based on the story generation model, whether a pronoun is included in the second story text is detected, and if the pronoun is included, a first attention weight and a preset second attention weight of each word in the second story text before the pronoun are acquired. In the preset second attention weight, the attention weight of the pronouns which refer to the same content with the pronouns is higher.
For example, the second story text includes "minired" meeting a pacifier on the way to school, and he holding the pacifier on the way, "where the first attention weight of" minired "is 0.2 and the second attention weight of" minired "is 0.8.
Optionally, if the story generation model includes an attention layer, obtaining a first attention weight of each term in the second story text before the pronoun may include: acquiring a first attention weight of each word before the pronoun output by the attention layer; alternatively, model parameters in the attention layer are replicated, and a first attention weight for each word preceding the pronoun is determined based on the model parameters.
The preset second attention weight may be input by the user or determined according to the context in the story text. For example, pronouns are words referring to characters, and referring chains can be set according to the characters appearing in the story text, wherein each referring chain comprises at least one pronoun referring to the same character; detecting each word in the story text, if detecting pronouns 1 included in a reference chain, determining whether other pronouns 2 in the reference chain are included in each word before the pronouns 1 according to all pronouns included in the reference chain, if the other pronouns 2 are included, determining a preset second attention weight for the included other pronouns 2, and determining the preset second attention weight of other words in each word before the pronouns 1 according to the preset second attention weight of the pronouns 2, so as to ensure that the sum of the preset second attention weights of each word before the pronouns 1 is 1.
Since the second story text generated by the story generation model may have a reference error problem, the pronouns in the second story text may be revised or marked with a reference entity by other tools or thought.
For example, if P characters appear in the processed second story text, we can obtain P reference chains, each reference chain includes q pronouns, where q is the number of times that the pronouns corresponding to the characters referred by the reference chain appear. According to the chain of references, each pronoun may be found in the second story text, and a preset second attention weight may be determined for each of at least one word preceding each pronoun.
504. And training the story generation model according to the first story text, the second story text, the first attention weight of each word and the preset second attention weight of each word.
If a large error exists between the first attention weight and the second attention weight, the pronouns generated in the second story text may have a problem of referring to errors. If the story generation model is trained according to the first attention weight of each word and the preset second attention weight of each word, the attention weight distribution of the words can be more accurate, and the generated pronouns are more accurate.
In one possible implementation, training the story generation model according to the first story text, the second story text, the first attention weight of each word, and the preset second attention weight of each word may include: determining a first loss value between the first story text and the second story text by adopting a loss function of the story generation model, wherein the first loss value and an error between the first story text and the second story text are in a positive correlation relationship; determining a fourth loss value between the first attention weight and the second attention weight of each word by adopting the loss function of the attention layer, wherein the fourth loss value is in positive correlation with the error between the first attention weight and the second attention weight of the corresponding word; and adjusting the model parameters of the story generation model according to the first loss value and the fourth loss value so as to converge the output values of the loss function of the story generation model and the loss function of the attention layer.
In one possible implementation, the loss function of the attention layer may employ the following formula:
Figure BDA0002422466800000261
wherein, L3Is a fourth loss value, p is the number of reference chains, q is the number of pronouns in each reference chain, pq is the total number of pronouns in the second story text, NiRepresenting the number of pronouns in the current chain of reference, ck=ciMeans that the kth word in the first i-1 words and the ith word are the same pronoun in the reference chain, wherein k is more than or equal to 1 and less than or equal to i-1, and xi (c)k=ci) Means that if the kth word of the first i-1 words and the ith word are pronouns in the same reference chain, then xi is 1, and if the kth word of the first i-1 words and the ith word are not pronouns in the same reference chain, then xi is 0, αikIs the first attention weight for the kth word of the first i-1 words.
Optionally, when the model parameters of the story generation model are adjusted according to the first loss value and the fourth loss value, the first loss value and the fourth loss value may be subjected to statistical processing, and the model parameters of the story generation model are adjusted according to the loss values obtained after the statistical processing. For example, if the influence of the first loss value on the story generation model is the same as the influence of the fourth loss value on the story generation model when the story generation model is adjusted, the sum of the first loss value and the fourth loss value may be obtained, and the model parameter of the story generation model may be adjusted based on the sum.
For another example, the first loss value has a large influence on the story generation model, the fourth loss value has a small influence on the story generation model, and the fourth loss value can be weighted according to the weight of the fourth loss value to obtain a fifth loss value, where the weight is used to indicate the influence degree of pronouns of the story text on the story text; and adjusting the model parameters of the story generation model according to the first loss value and the fifth loss value.
Optionally, adjusting the model parameters of the story generation model according to the first loss value and the fifth loss value may comprise: and acquiring the sum of the first loss value and the fifth loss value, and adjusting the model parameters of the story generation model according to the sum.
The story generation model training method provided by the embodiment of the application also considers the distribution of the attention weight of each word before the pronouns in the pronouns generation process in the training process, so that the accuracy of the story generation model is improved, when the pronouns in the story text are generated based on the trained story generation model, the referring entity in at least one word in the front can be more concerned, the generated pronouns are higher in accuracy, a user can more easily understand stories stated by the story text when reading the story text, and the user experience is improved.
It should be noted that the story model training method indicated in fig. 3 and fig. 5 may also be adopted to train the story generation model, and the following embodiment describes the training process of the story model by taking the combined story model training method as an example, where the training method of the story outline generation model may refer to the training method of the story generation model, and is not described in detail herein.
Fig. 6 is a flowchart of a story generation model training method provided in an embodiment of the present application. An execution subject of the embodiment of the present application is a computer device, and referring to fig. 6, the method includes:
601. and acquiring a first sample prompt text, a first story text and a first logic text corresponding to the first sample prompt text.
Wherein the first logical text is used to indicate a contextual logical relationship of the first story text.
Step 601 is similar to step 301 and step 501, and is not described in detail here.
602. And based on the story generation model, continuously generating at least one word according to the first sample prompt text, the generated at least one word and the first attention weight of each word in the at least one word to obtain a second story text containing a plurality of words.
Wherein the first attention weight is determined by the story generation model.
Step 602 is similar to step 502, and is not described in detail herein.
603. And generating a second logic text corresponding to the second story text based on the logic generation model.
Step 603 is similar to step 303, and is not described in detail here.
604. And if the pronouns are included in the second story text, acquiring a first attention weight and a preset second attention weight of each word before the pronouns in the second story text.
Step 604 is similar to step 503 and will not be described in detail here.
605. And training the story generation model according to the first story text, the second story text, the first logic text, the second logic text, the first attention weight of each word and the preset second attention weight of each word.
Step 605 is similar to step 304 and step 504, and is not described in detail here. Step 605 differs from step 304 and step 504 in that: in step 605, the influence of the story text, the logic text and the attention weight is comprehensively considered when the story generation model is trained.
In one possible implementation, the story generation model includes an attention layer, and training the story generation model according to the first story text, the second story text, the first logical text, the second logical text, the first attention weight and the second attention weight for each word may include: determining a first loss value between the first story text and the second story text by adopting a loss function of the story generation model, wherein the first loss value and an error between the first story text and the second story text are in a positive correlation relationship; determining a second loss value between the first logic text and the second logic text by adopting a loss function of the logic generation model, wherein the second loss value and the error between the first logic text and the second logic text are in positive correlation; determining a fourth loss value between the first attention weight and the second attention weight of each word by adopting the loss function of the attention layer, wherein the fourth loss value is in positive correlation with the error between the first attention weight and the second attention weight of the corresponding word; and adjusting the model parameters of the story generation model according to the first loss value, the second loss value and the fourth loss value so as to converge the output values of the loss function of the story generation model, the loss function of the logic generation model and the loss function of the attention layer.
Optionally, the first loss value has a large influence on the story generation model, the second loss value has a small influence on the story generation model, and the fourth loss value has a small influence on the story generation model, and the second loss value may be weighted according to the weight of the second loss value to obtain a third loss value, and the fourth loss value may be weighted according to the weight of the fourth loss value to obtain a fifth loss value; and adjusting the model parameters of the story generation model according to the first loss value, the third loss value and the fifth loss value.
For example, L ═ L11L22L3Wherein λ is1For the weight corresponding to the second loss value, λ2The weight corresponding to the fourth loss value. Wherein λ is1And λ2Is [0,1 ]]Any value in between.
By adopting the story generation model training method provided by the embodiment of the application, when the story generation model is trained, the second story text output by the story generation model can be used as the input of the logic generation model, the logic generation model generates the second logic text corresponding to the second story text, wherein the logic text is used for indicating the context logic relationship of the story text, the story generation model is trained according to the first story text, the second story text, the first logic text and the second logic text, and in the training process, the context logic of the story text is considered, so that the accuracy of the story generation model is improved, and the context logic of the story text generated by the story generation model is improved.
In addition, in the training process, the distribution of the attention weight of each word before the pronouns in the pronouns generation process is also considered, and the accuracy of the story generation model is improved, so that the accuracy of the pronouns is higher in the story text generated based on the trained story generation model, a user can understand stories stated by the story text more easily when reading the story text, and the user experience is improved.
Fig. 7 is a schematic structural diagram of a story generation model training apparatus provided in an embodiment of the present application, and referring to fig. 7, the apparatus includes: an acquisition module 701, a story generation module 702, a logic generation module 703, and a training module 704.
An obtaining module 701, configured to obtain a first sample prompt text, a first story text corresponding to the first sample prompt text, and a first logic text, where the first logic text is used to indicate a context logic relationship of the first story text;
a story generation module 702, configured to generate a second story text corresponding to the first sample prompt text based on a story generation model;
a logic generation module 703, configured to generate a second logic text corresponding to the second story text based on a logic generation model;
a training module 704 for training the story generation model according to the first story text, the second story text, the first logic text and the second logic text.
As shown in fig. 8, optionally, the training module 704 includes:
a first determining unit 7041, configured to determine a first loss value between the first story text and the second story text by using a loss function of the story generation model, where the first loss value and an error between the first story text and the second story text are in a positive correlation;
a second determining unit 7042, configured to determine a second loss value between the first logic text and the second logic text by using a loss function of the logic generation model, where the second loss value and an error between the first logic text and the second logic text are in a positive correlation;
an adjusting unit 7043 is configured to adjust a model parameter of the story generation model according to the first loss value and the second loss value, so that an output value of a loss function of the story generation model and an output value of a loss function of the logic generation model converge.
Optionally, the adjusting unit 7043 is further configured to perform weighting processing on the second loss value according to a weight of the second loss value to obtain a third loss value, where the weight is used to indicate an influence degree of a context logical relationship of a story text on the story text;
the adjusting unit 7043 is further configured to adjust a model parameter of the story generation model according to the first loss value and the third loss value.
Optionally, the logic generating module 703 is further configured to process at least two adjacent sentences in the second story text based on the logic generating model to obtain a logic keyword corresponding to the at least two sentences, where the logic keyword is used to indicate a context logic relationship of the at least two sentences.
Optionally, the logic generation model includes an encoding layer and a text output layer, and the logic generation module 703 includes:
a coding unit 7031, configured to obtain, based on the coding layer, a vector corresponding to each of the at least two statements, and perform fusion processing on the obtained at least two vectors to obtain a feature vector;
a text output unit 7032, configured to determine, based on the text output layer and according to the feature vector, a logic keyword corresponding to the at least two sentences.
Optionally, the story generation module 702 includes:
an input unit 7021 configured to input the first sample prompt text into the story generation model;
a generating unit 7022, configured to generate at least one word corresponding to the first sample prompt text according to the first sample prompt text based on the story generation model;
the generating unit 7022 is further configured to continue to generate at least one word according to the first sample prompt text and the at least one word that has been generated based on the story generation model until the number of generated words reaches a first preset number threshold, so as to obtain a second story text composed of the generated multiple words.
Optionally, the generating unit 7022 is further configured to determine, based on the story generation model, a first attention weight of each of the at least one word according to the first sample prompt text and the at least one word that has been generated;
the generating unit 7022 is further configured to continue generating at least one word according to the first sample prompt text, the at least one word, and the first attention weight of each word based on the story generation model.
Optionally, the training module 704 is further configured to, if the second story text includes a pronoun, obtain a first attention weight and a preset second attention weight of each word in the second story text before the pronoun;
the training module 704 is further configured to train the story generation model according to the first story text, the second story text, the first logic text, the second logic text, the first attention weight of each word, and the preset second attention weight of each word.
Optionally, the story generation model includes an attention layer, and the training module 704 includes:
a first determining unit 7041, configured to determine a first loss value between the first story text and the second story text by using a loss function of the story generation model, where the first loss value and an error between the first story text and the second story text are in a positive correlation;
a second determining unit 7042, configured to determine a second loss value between the first logic text and the second logic text by using a loss function of the logic generation model, where the second loss value and an error between the first logic text and the second logic text are in a positive correlation;
a third determining unit 7044, configured to determine, by using the loss function of the attention layer, a fourth loss value between the first attention weight and the second attention weight of each word, where the fourth loss value is in a positive correlation with an error between the first attention weight and the second attention weight of the corresponding word;
an adjusting unit 7043, configured to adjust the model parameters of the story generation model according to the first loss value, the second loss value, and the fourth loss value, so that output values of the loss function of the story generation model, the loss function of the logic generation model, and the loss function of the attention layer converge.
Optionally, the story generation module 702 includes:
an obtaining unit 7023, configured to obtain a first story outline text corresponding to the first sample prompt text;
a generating unit 7022 is configured to generate, based on the story generation model, a second story text corresponding to the first sample prompt text and the first story outline text.
Optionally, the obtaining unit 7023 is further configured to generate a first story outline text corresponding to the first sample prompt text based on the trained story outline generation model.
Optionally, the apparatus further comprises:
the obtaining module 701 is further configured to obtain a second sample prompt text and a second story outline text corresponding to the second sample prompt text;
the outline generating module 705 is configured to generate a third story outline text corresponding to the second sample prompt text based on the story outline generating model;
the training module 704 is further configured to train the story outline generation model according to the second story outline text and the third story outline text.
Optionally, the training module 704 is further configured to train the logical classification model according to the first logical text and the second logical text.
Optionally, the logic keyword includes: at least one of accept, turn, parallel and time.
It should be noted that: the story generation model training device provided in the above embodiment is exemplified by only the division of the functional modules when training the story generation model, and in practical applications, the function distribution may be completed by different functional modules as needed, that is, the internal structure of the computer device is divided into different functional modules to complete all or part of the functions described above. In addition, the story generation model training device provided by the above embodiment and the story generation model training method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment and is not described herein again.
Fig. 9 is a schematic structural diagram of a story text generation apparatus provided in an embodiment of the present application, and referring to fig. 9, the apparatus includes: a module 901 is generated.
The generating module 901 is configured to generate a story text corresponding to any prompt text based on a story generation model, where the story generation model is obtained by training using the apparatuses shown in fig. 7 and 8.
It should be noted that: the story text generation device provided in the above embodiment is only illustrated by the division of the functional modules when generating the story text, and in practical applications, the function distribution may be completed by different functional modules according to needs, that is, the internal structure of the computer device is divided into different functional modules to complete all or part of the functions described above. In addition, the story text generation apparatus provided by the above embodiment and the story text generation method embodiment belong to the same concept, and specific implementation processes thereof are detailed in the method embodiment and are not described herein again.
Fig. 10 is a block diagram of a terminal according to an embodiment of the present disclosure, where the terminal 1000 is configured to perform the steps performed by the terminal or the smart device according to the above embodiments, and may be a portable mobile terminal, such as a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio L layer III, motion Picture Experts Group Audio layer 3), an MP4 player (Moving Picture Experts Group Audio L layer IV, motion Picture Experts Group Audio layer 4), a notebook computer, or a desktop computer.
In general, terminal 1000 can include: a processor 1001 and a memory 1002.
The processor 1001 may include one or more Processing cores, such as a 4-core processor, an 8-core processor, etc., the processor 1001 may be implemented in at least one hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), a P L a (Programmable logic Array), the processor 1001 may also include a main processor and a coprocessor, the main processor is a processor for Processing data in a wake-up state, also known as a CPU (Central Processing Unit), the coprocessor is a low-power processor for Processing data in a standby state, in some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit) for rendering and rendering content desired for a display screen, and in some embodiments, the processor 1001 may also include an AI (intelligent processor 1001 for learning operations related to an AI processor).
Memory 1002 may include one or more computer-readable storage media, which may be non-transitory. The memory 1002 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In some embodiments, a non-transitory computer readable storage medium in memory 1002 is used to store at least one instruction for execution by processor 1001 to implement a story generation model training method and a story text generation method provided by method embodiments herein.
In some embodiments, terminal 1000 can also optionally include: a peripheral interface 1003 and at least one peripheral. The processor 1001, memory 1002 and peripheral interface 1003 may be connected by a bus or signal line. Various peripheral devices may be connected to peripheral interface 1003 via a bus, signal line, or circuit board. Specifically, the peripheral device includes: at least one of radio frequency circuitry 1004, touch screen display 1005, camera assembly 1006, audio circuitry 1007, positioning assembly 1008, and power supply 10010.
The peripheral interface 1003 may be used to connect at least one peripheral related to I/O (Input/Output) to the processor 1001 and the memory 1002. In some embodiments, processor 1001, memory 1002, and peripheral interface 1003 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1001, the memory 1002, and the peripheral interface 1003 may be implemented on separate chips or circuit boards, which are not limited in this application.
The Radio Frequency circuit 1004 is used for receiving and transmitting RF (Radio Frequency) signals, also called electromagnetic signals. The radio frequency circuitry 1004 communicates with communication networks and other communication devices via electromagnetic signals. The radio frequency circuit 1004 converts an electrical signal into an electromagnetic signal to transmit, or converts a received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 1004 comprises: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a subscriber identity module card, and so forth. The radio frequency circuit 1004 may communicate with other terminals via at least one wireless communication protocol. The wireless communication protocols include, but are not limited to: the world wide web, metropolitan area networks, intranets, generations of mobile communication networks (2G, 3G, 4G, and 5G), Wireless local area networks, and/or WiFi (Wireless Fidelity) networks. In some embodiments, the rf circuit 1004 may further include NFC (Near Field Communication) related circuits, which are not limited in this application.
Display 1005 is for displaying a UI (User Interface) that may include graphics, text, icons, video, and any combination thereof, when Display 1005 is a touch Display, Display 1005 also has the ability to capture touch signals on or over the surface of Display 1005. the touch signals may be input to processor 1001 for processing as control signals.
The camera assembly 1006 is used to capture images or video. Optionally, the camera assembly 1006 includes a front camera and a rear camera. Generally, a front camera is disposed at a front panel of the terminal, and a rear camera is disposed at a rear surface of the terminal. In some embodiments, the number of the rear cameras is at least two, and each rear camera is any one of a main camera, a depth-of-field camera, a wide-angle camera and a telephoto camera, so that the main camera and the depth-of-field camera are fused to realize a background blurring function, and the main camera and the wide-angle camera are fused to realize panoramic shooting and VR (Virtual Reality) shooting functions or other fusion shooting functions. In some embodiments, camera assembly 1006 may also include a flash. The flash lamp can be a monochrome temperature flash lamp or a bicolor temperature flash lamp. The double-color-temperature flash lamp is a combination of a warm-light flash lamp and a cold-light flash lamp, and can be used for light compensation at different color temperatures.
The audio circuit 1007 may include a microphone and a speaker. The microphone is used for collecting sound waves of a user and the environment, converting the sound waves into electric signals, and inputting the electric signals to the processor 1001 for processing or inputting the electric signals to the radio frequency circuit 1004 for realizing voice communication. For stereo sound collection or noise reduction purposes, multiple microphones can be provided, each at a different location of terminal 1000. The microphone may also be an array microphone or an omni-directional pick-up microphone. The speaker is used to convert electrical signals from the processor 1001 or the radio frequency circuit 1004 into sound waves. The loudspeaker can be a traditional film loudspeaker or a piezoelectric ceramic loudspeaker. When the speaker is a piezoelectric ceramic speaker, the speaker can be used for purposes such as converting an electric signal into a sound wave audible to a human being, or converting an electric signal into a sound wave inaudible to a human being to measure a distance. In some embodiments, the audio circuit 1007 may also include a headphone jack.
The positioning component 1008 is used to position the current geographic location of the terminal 1000 to implement navigation or L BS (L geographic based Service). the positioning component 1008 can be a positioning component based on the GPS (global positioning System) in the united states, the beidou System in china, or the greiner System in russia, or the galileo System in the european union.
Power supply 1009 is used to supply power to various components in terminal 1000. The power source 1009 may be alternating current, direct current, disposable batteries, or rechargeable batteries. When the power source 1009 includes a rechargeable battery, the rechargeable battery may support wired charging or wireless charging. The rechargeable battery may also be used to support fast charge technology.
Those skilled in the art will appreciate that the configuration shown in FIG. 10 is not intended to be limiting and that terminal 1000 can include more or fewer components than shown, or some components can be combined, or a different arrangement of components can be employed.
Fig. 11 is a schematic structural diagram of a server according to an embodiment of the present application, where the server 1100 may generate a relatively large difference due to a difference in configuration or performance, and may include one or more processors (CPUs) 1101 and one or more memories 1102, where the memory 1102 stores at least one instruction, and the at least one instruction is loaded and executed by the processors 1101 to implement the methods provided by the foregoing method embodiments. Of course, the server may also have components such as a wired or wireless network interface, a keyboard, and an input/output interface, so as to perform input/output, and the server may also include other components for implementing the functions of the device, which are not described herein again.
The server 1100 may be used to perform the steps performed by the server in the story generation model training method and story text generation method described above.
The embodiment of the present application further provides a computer device, where the computer device includes a processor and a memory, where the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the operations executed in the story generation model training method of the foregoing embodiment; or to implement the operations performed in the story text generation method of the above-described embodiments.
The embodiment of the present application further provides a computer-readable storage medium, where at least one instruction is stored in the computer-readable storage medium, and the at least one instruction is loaded and executed by a processor to implement the operations executed in the story generation model training method of the foregoing embodiment; or to implement the operations performed in the story text generation method of the above-described embodiments.
The embodiment of the present application further provides a computer program, where at least one instruction is stored in the computer program, and the at least one instruction is loaded and executed by a processor to implement the operations executed in the story generation model training method of the foregoing embodiment; or to implement the operations performed in the story text generation method of the above-described embodiments.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only exemplary of the present application and should not be taken as limiting, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims (15)

1. A story generation model training method, the method comprising:
acquiring a first sample prompt text, a first story text corresponding to the first sample prompt text and a first logic text, wherein the first logic text is used for indicating the context logic relationship of the first story text;
generating a second story text corresponding to the first sample prompt text based on a story generation model;
generating a second logic text corresponding to the second story text based on a logic generation model;
and training the story generation model according to the first story text, the second story text, the first logic text and the second logic text.
2. The method of claim 1, wherein training the story generation model based on the first story text, the second story text, the first logic text, and the second logic text comprises:
determining a first loss value between the first story text and the second story text by adopting a loss function of the story generation model, wherein the first loss value and an error between the first story text and the second story text are in a positive correlation relationship;
determining a second loss value between the first logic text and the second logic text by adopting a loss function of the logic generation model, wherein the second loss value and an error between the first logic text and the second logic text are in a positive correlation relationship;
and adjusting the model parameters of the story generation model according to the first loss value and the second loss value so as to converge the output values of the loss function of the story generation model and the loss function of the logic generation model.
3. The method of claim 1, wherein generating a second logical text corresponding to the second story text based on a logical generative model comprises:
processing at least two adjacent sentences in the second story text based on the logic generation model to obtain logic keywords corresponding to the at least two sentences, wherein the logic keywords are used for indicating the context logic relationship of the at least two sentences.
4. The method of claim 3, wherein the logic generation model includes an encoding layer and a text output layer, and the processing at least two adjacent sentences in the second story text based on the logic generation model to obtain logic keywords corresponding to the at least two sentences includes:
acquiring a vector corresponding to each statement in the at least two statements based on the coding layer, and performing fusion processing on the acquired at least two vectors to obtain a feature vector;
and determining logic keywords corresponding to the at least two sentences according to the feature vectors based on the text output layer.
5. The method of claim 1, wherein generating a second story text corresponding to the first sample prompt text based on a story generation model comprises:
inputting the first sample prompt text into the story generation model;
generating at least one word corresponding to the first sample prompt text according to the first sample prompt text based on the story generation model;
and based on the story generation model, continuously generating at least one word according to the first sample prompt text and the generated at least one word until the number of the generated words reaches a first preset number threshold value, and obtaining a second story text formed by the generated words.
6. The method of claim 5, wherein continuing to generate at least one term from the first sample prompt text and the at least one term that has been generated based on the story generation model comprises:
determining a first attention weight for each of the at least one word from the first sample prompt text and the at least one word that has been generated based on the story generation model;
continuing to generate at least one word in accordance with the first sample prompt text, the at least one word, and the first attention weight for each word based on the story generation model.
7. The method of claim 6, wherein training the story generation model based on the first story text, the second story text, the first logic text, and the second logic text comprises:
if the second story text comprises pronouns, acquiring a first attention weight and a preset second attention weight of each word before the pronouns in the second story text;
training the story generation model according to the first story text, the second story text, the first logic text, the second logic text, the first attention weight of each word and a second attention weight preset by each word.
8. The method of claim 7, wherein the story generation model includes an attention layer, and wherein training the story generation model based on the first story text, the second story text, the first logical text, the second logical text, the first attention weight and the second attention weight for each word comprises:
determining a first loss value between the first story text and the second story text by adopting a loss function of the story generation model, wherein the first loss value and an error between the first story text and the second story text are in a positive correlation relationship;
determining a second loss value between the first logic text and the second logic text by adopting a loss function of the logic generation model, wherein the second loss value and an error between the first logic text and the second logic text are in a positive correlation relationship;
determining a fourth loss value between the first attention weight and the second attention weight of each word by adopting the loss function of the attention layer, wherein the fourth loss value is in positive correlation with the error between the first attention weight and the second attention weight of the corresponding word;
adjusting model parameters of the story generation model according to the first loss value, the second loss value and the fourth loss value so that output values of a loss function of the story generation model, a loss function of the logic generation model and a loss function of the attention layer converge.
9. The method of claim 1, wherein generating a second story text corresponding to the first sample prompt text based on a story generation model comprises:
acquiring a first story outline text corresponding to the first sample prompt text;
and generating a second story text corresponding to the first sample prompt text and the first story outline text based on the story generation model.
10. The method of claim 1, wherein after generating a second logical text corresponding to the second story text based on the logical generative model, the method further comprises:
and training the logic classification model according to the first logic text and the second logic text.
11. A story text generation method, the method comprising:
and generating story text corresponding to any prompt text based on a story generation model, wherein the story generation model is obtained by training by adopting the method of any one of claims 1 to 10.
12. A story generation model training apparatus, the apparatus comprising:
the system comprises an acquisition module, a judgment module and a display module, wherein the acquisition module is used for acquiring a first sample prompt text, a first story text and a first logic text corresponding to the first sample prompt text, and the first logic text is used for indicating the context logic relationship of the first story text;
the story generation module is used for generating a second story text corresponding to the first sample prompt text based on a story generation model;
the logic generation module is used for generating a second logic text corresponding to the second story text based on a logic generation model;
and the training module is used for training the story generation model according to the first story text, the second story text, the first logic text and the second logic text.
13. A story text generation apparatus, the apparatus comprising:
a generating module, configured to generate a story text corresponding to any prompt text based on a story generation model, where the story generation model is obtained by training using the apparatus according to claim 12.
14. A computer device comprising a processor and a memory, the memory having stored therein at least one instruction, the at least one instruction being loaded and executed by the processor to perform operations performed in the story generation model training method of any one of claims 1 to 10; or to implement the operations performed in the story text generation method of claim 11.
15. A computer-readable storage medium having stored therein at least one instruction, which is loaded and executed by the processor, to implement the operations performed in the story generation model training method according to any one of claims 1 to 10; or to implement the operations performed in the story text generation method of claim 11.
CN202010209921.4A 2020-03-23 2020-03-23 Story generation model training method, device, equipment and storage medium Active CN111414736B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010209921.4A CN111414736B (en) 2020-03-23 2020-03-23 Story generation model training method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010209921.4A CN111414736B (en) 2020-03-23 2020-03-23 Story generation model training method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111414736A true CN111414736A (en) 2020-07-14
CN111414736B CN111414736B (en) 2022-05-20

Family

ID=71493181

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010209921.4A Active CN111414736B (en) 2020-03-23 2020-03-23 Story generation model training method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111414736B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113342943A (en) * 2021-08-05 2021-09-03 北京明略软件系统有限公司 Training method and device for classification model
CN113515951A (en) * 2021-07-19 2021-10-19 同济大学 Story description generation method based on knowledge enhanced attention network and group-level semantics
CN114139524A (en) * 2021-11-29 2022-03-04 浙江大学 Method and device for predicting story text and electronic equipment
CN114492456A (en) * 2022-01-26 2022-05-13 北京百度网讯科技有限公司 Text generation method, model training method, device, electronic equipment and medium
CN115081402A (en) * 2022-07-13 2022-09-20 平安科技(深圳)有限公司 Story plot expansion method, device, equipment and medium based on traceability reasoning
WO2023088309A1 (en) * 2021-11-19 2023-05-25 北京有竹居网络技术有限公司 Method for rewriting narrative text, device, apparatus, and medium
CN117033934A (en) * 2023-08-02 2023-11-10 中信联合云科技有限责任公司 Content generation method and device based on artificial intelligence

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030048308A1 (en) * 2001-09-13 2003-03-13 L/R Services, Inc. System and method for generating an online interactive story
CN101261690A (en) * 2008-04-18 2008-09-10 北京百问百答网络技术有限公司 A system and method for automatic problem generation
CN109670174A (en) * 2018-12-14 2019-04-23 腾讯科技(深圳)有限公司 A kind of training method and device of event recognition model
CN109684473A (en) * 2018-12-28 2019-04-26 丹翰智能科技(上海)有限公司 A kind of automatic bulletin generation method and system
KR20190058870A (en) * 2017-11-22 2019-05-30 전자부품연구원 Apparatus for making story based on news articles, method thereof and computer recordable medium storing program to perform the method
CN110209807A (en) * 2018-07-03 2019-09-06 腾讯科技(深圳)有限公司 A kind of method of event recognition, the method for model training, equipment and storage medium
CN110209803A (en) * 2019-06-18 2019-09-06 腾讯科技(深圳)有限公司 Story generation method, device, computer equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030048308A1 (en) * 2001-09-13 2003-03-13 L/R Services, Inc. System and method for generating an online interactive story
CN101261690A (en) * 2008-04-18 2008-09-10 北京百问百答网络技术有限公司 A system and method for automatic problem generation
KR20190058870A (en) * 2017-11-22 2019-05-30 전자부품연구원 Apparatus for making story based on news articles, method thereof and computer recordable medium storing program to perform the method
CN110209807A (en) * 2018-07-03 2019-09-06 腾讯科技(深圳)有限公司 A kind of method of event recognition, the method for model training, equipment and storage medium
CN109670174A (en) * 2018-12-14 2019-04-23 腾讯科技(深圳)有限公司 A kind of training method and device of event recognition model
CN109684473A (en) * 2018-12-28 2019-04-26 丹翰智能科技(上海)有限公司 A kind of automatic bulletin generation method and system
CN110209803A (en) * 2019-06-18 2019-09-06 腾讯科技(深圳)有限公司 Story generation method, device, computer equipment and storage medium

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113515951A (en) * 2021-07-19 2021-10-19 同济大学 Story description generation method based on knowledge enhanced attention network and group-level semantics
CN113515951B (en) * 2021-07-19 2022-07-05 同济大学 Story description generation method based on knowledge enhanced attention network and group-level semantics
CN113342943A (en) * 2021-08-05 2021-09-03 北京明略软件系统有限公司 Training method and device for classification model
WO2023088309A1 (en) * 2021-11-19 2023-05-25 北京有竹居网络技术有限公司 Method for rewriting narrative text, device, apparatus, and medium
CN114139524A (en) * 2021-11-29 2022-03-04 浙江大学 Method and device for predicting story text and electronic equipment
CN114492456A (en) * 2022-01-26 2022-05-13 北京百度网讯科技有限公司 Text generation method, model training method, device, electronic equipment and medium
CN115081402A (en) * 2022-07-13 2022-09-20 平安科技(深圳)有限公司 Story plot expansion method, device, equipment and medium based on traceability reasoning
CN115081402B (en) * 2022-07-13 2023-05-09 平安科技(深圳)有限公司 Storyline expansion method, device, equipment and medium based on traceability reasoning
CN117033934A (en) * 2023-08-02 2023-11-10 中信联合云科技有限责任公司 Content generation method and device based on artificial intelligence
CN117033934B (en) * 2023-08-02 2024-04-19 中信联合云科技有限责任公司 Content generation method and device based on artificial intelligence

Also Published As

Publication number Publication date
CN111414736B (en) 2022-05-20

Similar Documents

Publication Publication Date Title
CN111414736B (en) Story generation model training method, device, equipment and storage medium
CN112347795B (en) Machine translation quality assessment method, device, equipment and medium
CN112069309B (en) Information acquisition method, information acquisition device, computer equipment and storage medium
JP7324838B2 (en) Encoding method and its device, apparatus and computer program
CN110162604B (en) Statement generation method, device, equipment and storage medium
CN110147533B (en) Encoding method, apparatus, device and storage medium
CN113515942A (en) Text processing method and device, computer equipment and storage medium
CN110555102A (en) media title recognition method, device and storage medium
CN114281956A (en) Text processing method and device, computer equipment and storage medium
CN111414737B (en) Story generation model training method, device, equipment and storage medium
CN111950255B (en) Poem generation method, device, equipment and storage medium
CN113836946B (en) Method, device, terminal and storage medium for training scoring model
CN113822084A (en) Statement translation method and device, computer equipment and storage medium
CN114333774A (en) Speech recognition method, speech recognition device, computer equipment and storage medium
CN110837557B (en) Abstract generation method, device, equipment and medium
CN117454954A (en) Model training method, device, computer equipment and storage medium
CN112287070A (en) Method and device for determining upper and lower position relation of words, computer equipment and medium
CN115116437B (en) Speech recognition method, device, computer equipment, storage medium and product
CN112988984B (en) Feature acquisition method and device, computer equipment and storage medium
CN114996515A (en) Training method of video feature extraction model, text generation method and device
CN116958851A (en) Training method, device, equipment and storage medium for video aging model
CN114328815A (en) Text mapping model processing method and device, computer equipment and storage medium
CN113537470A (en) Model quantization method and device, storage medium and electronic device
CN113823266A (en) Keyword detection method, device, equipment and storage medium
CN113515943A (en) Natural language processing method and method, device and storage medium for acquiring model thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40026166

Country of ref document: HK

GR01 Patent grant
GR01 Patent grant