Text generation method and device, computer equipment and computer readable storage medium

By encoding and processing the information to be processed, target text information with emotional attributes and logic is generated, which solves the emotional and logical shortcomings of existing AI-generated plot texts and improves the immersive experience of the game.

CN119896857APending Publication Date: 2025-04-29TCL TECHNOLOGY GROUP CORPORATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311408023.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-26
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

The existing plot text generated based on AI has shortcomings in terms of emotional attributes and logic, resulting in reduced fluency, coherence and fun of the game, and poor player experience of immersive experience.

Method used

By obtaining the information to be processed and the emotional attribute information, the information to be processed is encoded and processed, and the target text information is generated, making it have emotional attributes and more logical and dramatic.

Benefits of technology

The generated target text information is more in line with the development of the plot, enhancing the fluency, coherence and fun of the text, and improving the immersive game experience of gamers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119896857A_ABST
    Figure CN119896857A_ABST
Patent Text Reader

Abstract

The invention discloses a text generation method and device, computer equipment and a computer readable storage medium. The method comprises the steps that to-be-processed information and emotional attribute information are acquired; encoding the to-be-processed information to obtain first encoding information of the to-be-processed information; and decoding the first coding information, the to-be-processed information and the emotion attribute information to obtain target text information. By adopting the method provided by the invention, the text expression which has an emotional attribute and is more logic-conforming and more dramatic and attractive can be generated, so that the generated target text is more fit with the development of a plot.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and in particular to a text generation method, apparatus, computer device and computer-readable storage medium. Background Art

[0002] In plot-generated games, players play games or interact with non-player characters (NPCs) through game plots, and the game plots are composed of plot texts. Therefore, plot texts need to be generated in plot-generated games. Traditional plot texts are pre-set by humans, which leads to problems such as plot repetition, established patterns, and fixed routines in plot games. In order to solve these technical problems, people began to use artificial intelligence (AI) to generate plot texts. However, existing plot texts generated based on AI often do not have emotional attributes and are not well matched to the development of the game plot, which weakens the fluency, coherence and fun of the game and reduces the player's immersive experience. Summary of the invention

[0003] The embodiments of the present application provide a text generation method, apparatus, computer device and computer-readable storage medium, which can generate text expressions with emotional attributes and are more logical, dramatic and attractive, so that the generated target text is more in line with the development of the plot.

[0004] The technical solution adopted by the present invention to solve the problem is as follows:

[0005] On the one hand, the present application provides a text generation method, comprising:

[0006] Obtaining information to be processed and emotional attribute information;

[0007] Encoding the information to be processed to obtain first coded information of the information to be processed;

[0008] The first coded information, the information to be processed and the emotional attribute information are decoded to obtain the target text information.

[0009] In some implementation schemes of the present application, encoding processing is performed on the information to be processed to obtain first encoded information of the information to be processed, including:

[0010] Extract and fuse features of the information to be processed to obtain first fused feature information of the information to be processed;

[0011] Filtering the first fused feature information based on the information to be processed to obtain second fused feature information;

[0012] Based on the second fused feature information, first encoding information of the information to be processed is determined.

[0013] In some implementation schemes of the present application, feature extraction and fusion are performed on the information to be processed to obtain first fused feature information of the information to be processed, including:

[0014] Perform feature extraction on the information to be processed to obtain first state information of each word in the information to be processed and second state information of each word;

[0015] Fusing the first state information of each word with the second state information of each word to obtain fused state information of each word;

[0016] The fusion state information of each word and the fusion state information of the neighboring words corresponding to each word are concatenated to obtain the concatenated state information of each word;

[0017] A convolution operation is performed on the splicing state information to obtain first fusion feature information of the information to be processed.

[0018] In some embodiments of the present application, filtering the first fused feature information based on the information to be processed to obtain the second fused feature information includes:

[0019] Perform a convolution operation on the information to be processed to obtain first feature information of the information to be processed;

[0020] fusing the first feature information and the first fused feature information to obtain third fused feature information;

[0021] Performing feature mapping on the third fused feature information to obtain fourth fused feature information;

[0022] The first fused feature information is filtered based on the fourth fused feature information to obtain second fused feature information.

[0023] In some embodiments of the present application, determining the first encoding information of the information to be processed based on the second fusion feature information includes:

[0024] Based on the second fused feature information, determining the second feature information and the third feature information;

[0025] Performing feature extraction on the second feature information to obtain fourth feature information;

[0026] fusing the fourth feature information and the third feature information to obtain fifth fused feature information;

[0027] Performing feature mapping on the fifth fused feature information to obtain mapped feature information;

[0028] The mapped feature information and the second feature information are fused to obtain first coded information of the information to be processed.

[0029] In some implementation schemes of the present application, the first coded information, the information to be processed and the emotional attribute information are decoded to obtain the target text information, including:

[0030] The information to be processed and the emotional attribute information are fused to obtain first fused information;

[0031] The first fused information and the first encoded information are decoded to obtain target text information.

[0032] In some implementation schemes of the present application, decoding the first fusion information and the first encoded information to obtain target text information includes:

[0033] Based on the first coding information, determining second coding information;

[0034] Normalize the second encoded information to obtain attention information;

[0035] Determining third encoding information based on the attention information and the first encoding information;

[0036] Decoding the third coded information and the first fused information to obtain decoded information;

[0037] Mapping the decoded information to obtain word distribution information;

[0038] Based on the word distribution information, the target text information is determined.

[0039] In a second aspect, an embodiment of the present invention further provides a text generation device, comprising:

[0040] An information acquisition unit, used to acquire information to be processed and emotional attribute information;

[0041] An information processing unit, used for encoding the information to be processed to obtain first encoded information of the information to be processed;

[0042] The text generation unit is used to decode the first coded information, the information to be processed and the emotional attribute information to obtain the target text information.

[0043] In a third aspect, the present application further provides a computer device, the computer device comprising:

[0044] one or more processors;

[0045] Memory; and

[0046] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement any one of the text generation methods in the first aspect.

[0047] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and the computer program is loaded by a processor to execute the steps in any one of the text generation methods in the first aspect.

[0048] The beneficial effects of the present invention are as follows: by encoding the information to be processed to obtain the first encoded information, and generating target text information based on the first encoded information and the information to be processed, a more logical, dramatic and attractive text expression can be generated in a plot generation game; by generating the target text information based on the emotional attribute information, a text with emotional attributes can be generated, so that the generated target text information is more in line with the development of the plot, the fluency, coherence and interest of the generated text are enhanced, and the immersive gaming experience of game players is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0050] Figure 1 It is a flowchart of a text generation method provided by an embodiment of the present invention;

[0051] Figure 2 is a specific structural diagram of a text generation model provided by an embodiment of the present invention;

[0052] Figure 3 is a principle block diagram of a text generation device provided by an embodiment of the present invention;

[0053] Figure 4 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0055] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings, which are only for the convenience of describing the present application and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, the terms "first", "second", "third" and the like are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, features defined as "first", "second", "third", etc. may explicitly or implicitly include one or more features. In the description of the present application, "multiple" means two or more, and "several" means one or more, unless otherwise clearly and specifically defined.

[0056] In this application, the word "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described in this application as "exemplary" is not necessarily to be construed as being preferred or advantageous over other embodiments. The following description is given to enable any technician in the field to implement and use the present application. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present application can be implemented without using these specific details. In other instances, well-known structures and processes will not be elaborated in detail to avoid obscuring the description of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in the present application.

[0057] It should be noted that since the method of the embodiment of the present application is executed in a computer device, the processing objects of each computer device exist in the form of data or information. For example, time is actually time information. It can be understood that if size, quantity, position, etc. are mentioned in subsequent embodiments, they are all corresponding data for processing by the computer device. The details will not be repeated here.

[0058] The inventor has found through research that the plot text of traditional plot generation games is usually pre-set by humans, and then the players choose the plot according to the preset options. Such plot generation games have problems such as repeated plots, established patterns, fixed routines, and lack of novelty. In order to solve the problems of traditional plot generation games, there are existing plot texts generated based on artificial intelligence (AI). The plot text generation method based on AI can generate a series of new plots according to the keywords input by the players, thereby getting rid of the limitations of the preset framework and increasing the novelty and challenge of the game. However, the existing plot text generation method based on AI has at least the following two problems: ① Since the plot game is developing towards a more complex story structure and a longer plot setting, the information extraction and text generation capabilities of the existing model are limited, and it is impossible to generate a plot that conforms to the content logic and time sequence; ② The generated text often does not have emotional attributes, and is not in line with the development of the game plot, which weakens the fluency, coherence and fun of the game, and reduces the immersive game experience of the game players.

[0059] Based on this, in an embodiment of the present application, information to be processed and emotional attribute information are obtained; the information to be processed is encoded to obtain first encoded information of the information to be processed; the first encoded information, the information to be processed and the emotional attribute information are decoded to obtain target text information, which can generate a text expression with emotional attributes and more logical, dramatic and attractive, so that the generated target text is more in line with the development of the plot, enhance the fluency, coherence and fun of the generated text, and improve the immersive gaming experience of game players.

[0060] The content of this application is further illustrated below through the description of embodiments in conjunction with the accompanying drawings.

[0061] This embodiment provides a text generation method, such as Figure 1 As shown in , the method includes:

[0062] Step S10: Obtain information to be processed and emotional attribute information.

[0063] The information to be processed is the prompt information in the text generation task. The information to be processed can be a set of keywords given in advance in the text generation task. The information to be processed can be expressed as C = {c1, c2, ..., c k}, c k represents the kth keyword in the information to be processed. The information to be processed may be one or more groups of words input by a user through a computer device (eg, a smart phone), or may be one or more groups of words obtained by converting speech to text from collected user conversations through a computer device.

[0064] The emotional attribute information is the emotional attribute category of the target text information that needs to be generated in the text generation task. The emotional attribute information contains the emotional attribute category of the words in the target text information. The emotional attribute information can be expressed as L1 = {l1, l2, ..., l s}, l s represents the sentiment attribute category of the s-th word in the target text information. For example, the sentiment label of positive text is 2, the sentiment label of negative text is 1, and the sentiment label of neutral text is 0. The sentiment attribute information of the text X = {She likes playing the guitar but hates singing songs} can be expressed as L1 = {0, 0, 2, 2, 2, 2, 0, 1, 1, 1, 0}, where 2 indicates that the sentiment attribute category of the word is positive, 1 indicates that the sentiment attribute category of the word is negative, the 0 at the beginning and the end indicate the start and end symbols, and 0 at other positions indicates that the sentiment attribute category of the word is neutral.

[0065] This embodiment obtains information to be processed and preset emotional attribute information, generates target text information based on the preset emotional attribute information and the information to be processed, and can generate target text information using the information to be processed as lexical constraints. It can generate more logical, dramatic and attractive text expressions in plot generation games, and the generated target text information has emotional attributes, so that the generated text is more in line with the development of the game plot, thereby improving the fluency, coherence and fun of the game and reducing the player's immersive gaming experience.

[0066] Step S20: Encode the information to be processed to obtain first encoded information of the information to be processed.

[0067] The first coded information is the coded information of the information to be processed obtained by encoding the information to be processed. Invalid information in the information to be processed is filtered out in the first coded information. The target text information is generated based on the first coded information, which can generate a more logical, dramatic and attractive text expression.

[0068] In a specific implementation, the text generation method is applied to a text generation model, such as Figure 2 The text generation model includes an encoder, and the step of encoding the information to be processed to obtain the first encoded information of the information to be processed specifically includes: inputting the information to be processed into the encoder, encoding the information to be processed through the encoder, and obtaining the first encoded information of the information to be processed.

[0069] In a specific implementation, step S20 includes:

[0070] Step S21, extracting and fusing features of the information to be processed to obtain first fused feature information of the information to be processed;

[0071] Step S22: filtering the first fused feature information based on the information to be processed to obtain second fused feature information;

[0072] Step S23: Determine first encoding information of the information to be processed based on the second fusion feature information.

[0073] The first fused feature information is a vector representation of the fused neighborhood word features of each word in the information to be processed, and the second fused feature information is the first fused feature information obtained by filtering invalid information from the first fused feature information based on the information to be processed. When encoding the information to be processed, this embodiment first extracts and fuses features of the information to be processed to obtain the first fused feature information of the information to be processed, then filters the first fused feature information based on the information to be processed to obtain the second fused feature information, and finally determines the first encoding information of the information to be processed based on the second fused feature information. Since the invalid information in the information to be processed is filtered out in the second fused feature information, the invalid information in the information to be processed is also filtered out in the first encoding information determined based on the second fused feature information. The target text information is generated based on the first encoding information, and a more logical, dramatic and attractive text expression can be generated.

[0074] In a specific implementation, step S21 includes:

[0075] Step S211, extracting features from the information to be processed to obtain first state information of each word and second state information of each word in the information to be processed;

[0076] Step S212: Fusing the first state information of each word with the second state information of each word to obtain fused state information of each word;

[0077] Step S213, concatenating the fusion state information of each word with the fusion state information of the neighboring words corresponding to each word to obtain concatenated state information of each word;

[0078] Step S214: performing a convolution operation on the splicing state information to obtain first fusion feature information of the information to be processed.

[0079] The first state information is the forward hidden state information of each word in the information to be processed, the second state information is the reverse hidden state information of each word in the information to be processed, and the fused state information is the fused information obtained by fusion of the forward hidden state information of each word and the reverse hidden state information of each word. The neighborhood words of each word are the words in the neighborhood interval with each word as the center word. The neighborhood words of the i-th word in the information to be processed can be expressed as k represents the neighborhood length of the i-th word in the information to be processed. The splicing state information is the splicing information obtained by splicing the fusion state information of each word and the fusion state information of the neighboring words corresponding to each word.

[0080] When extracting and fusing features of the information to be processed, this embodiment first extracts features of the information to be processed to obtain the first state information of each word and the second state information of each word in the information to be processed. For example, the information to be processed can be input into a Bi-LSTM model, and the information to be processed can be extracted by the Bi-LSTM model. The second state information of the word, c i represents the i-th word in the information to be processed, W q 、V q 、h q , W h 、V h , b h represents a learnable parameter.

[0081] After obtaining the first state information of each word and the second state information of each word, the first state information of each word and the second state information of each word are fused to obtain the fused state information of each word. The process of fusing the first state information and the second state information can be expressed as: h i Indicates the fusion status information of the i-th word in the information to be processed, represents the first state information of the i-th word in the information to be processed, Represents the second state information of the i-th word in the information to be processed.

[0082] After obtaining the fusion state information of each word, the fusion state information of each word and the fusion state information of the neighboring words corresponding to each word are concatenated to obtain the concatenated state information of each word, and then the concatenated state information is subjected to sliding convolution operation with each word as the central word to obtain the first fusion feature information of the information to be processed. The first fusion feature information can be expressed as: b), g i represents the first fused feature information of the i-th word in the information to be processed, conv represents the convolution operation, Indicates the number of pending information The fusion state information of words, Indicates the number of pending information The fusion status information of words, [] indicates the concatenation operation, W C and b represent learnable parameters.

[0083] In a specific implementation, step S22 includes:

[0084] Step S221, performing a convolution operation on the information to be processed to obtain first feature information of the information to be processed;

[0085] Step S222: Fusing the first feature information and the first fused feature information to obtain third fused feature information;

[0086] Step S223: performing feature mapping on the third fused feature information to obtain fourth fused feature information;

[0087] Step S224: Filter the first fused feature information based on the fourth fused feature information to obtain second fused feature information.

[0088] The first characteristic information is a keyword feature representation of the information to be processed obtained by performing a convolution operation on the information to be processed. The step of performing a convolution operation on the information to be processed may specifically include: determining a keyword information representation matrix of the information to be processed, performing a convolution operation on the keyword information representation matrix, and obtaining the first characteristic information of the information to be processed. The determination process of the first characteristic information can be expressed as: G = conv(W g A+b g ), G represents the first feature information, conv represents the convolution operation, A represents the keyword information representation matrix, W g and b g represents a learnable parameter.

[0089] After obtaining the first feature information of the information to be processed, the first feature information and the first fused feature information are fused to obtain the third fused feature information, and the third fused feature information is feature mapped using the preset first activation function to obtain the fourth fused feature information. The determination process of the fourth fused feature information can be expressed as: f =σ(W f [G,g i ]+b f ), g f Indicates the fourth fusion feature information, G indicates the first feature information, g i represents the first fusion feature information, W f and b f represents a learnable parameter, σ represents the first activation function, and σ can be set as needed. For example, σ can adopt a sigmoid function.

[0090] After obtaining the fourth fusion feature information, the first fusion feature information is filtered based on the fourth fusion feature information to obtain the second fusion feature information. Specifically, when the fourth fusion feature information is close to 0, the information filtering based on the fourth fusion feature information on the first fusion feature information can delete most of the information on the corresponding dimension of the first fusion feature information. When the fourth fusion feature information is close to 1, the information filtering based on the fourth fusion feature information on the first fusion feature information can retain most of the information on the corresponding dimension of the first fusion feature information. Among them, the process of filtering the first fusion feature information based on the fourth fusion feature information can be expressed as: g i '=g i ·g f , g i ' represents the second fusion feature information, g i represents the first fusion feature information, g f Represents the fourth fusion feature information.

[0091] In a specific implementation, step S23 includes:

[0092] Step S231: Determine the second feature information and the third feature information based on the second fused feature information;

[0093] Step S232: extracting features from the second feature information to obtain fourth feature information;

[0094] Step S233: Fusing the fourth feature information and the third feature information to obtain fifth fused feature information;

[0095] Step S234, performing feature mapping on the fifth fused feature information to obtain mapped feature information;

[0096] Step S235: merge the mapped feature information and the second feature information to obtain first coded information of the information to be processed.

[0097] The second fused feature information can be represented by two representation matrices. The second feature information and the third feature information are two representation matrices used to represent the second fused feature information. That is, the second feature information and the third feature information constitute the second fused feature information. The fourth feature information is feature information obtained by extracting features from the second feature information. The calculation formula of the fourth feature information is: K = W att V, K represents the fourth feature information, V represents the second feature information, W att represents the learnable parameter matrix.

[0098] The fifth fused feature information is feature information obtained by fusing the fourth feature information and the third feature information. The fifth fused feature information can be expressed as: Among them, R1 represents the fifth fusion feature information, Q represents the third feature information, K represents the fourth feature information, d k Represents the vector dimension of the fourth feature information K.

[0099] After obtaining the fifth fused feature information, feature mapping is performed on the fifth fused feature information based on a preset second activation function to obtain mapping feature information, wherein the second activation function can be set as needed. For example, when the second activation function adopts a softmax function, the mapping feature information can be expressed as: R2=softmax(R1), wherein R1 represents the fifth fused feature information, Q represents the third feature information, K represents the fourth feature information, and d k Represents the vector dimension of the fourth feature information K.

[0100] After the mapping feature information is obtained, the mapping feature information and the second feature information are fused to obtain the first coded information of the information to be processed. The first coded information can be expressed as: Among them, R represents the first coding information, R2 represents the mapping characteristic information, and V represents the second characteristic information.

[0101] Step S30: Decode the first coded information, the information to be processed and the emotional attribute information to obtain the target text information.

[0102] The target text information is a plot text description generated based on the coded information, the information to be processed and the emotional attribute information. For example, the information to be processed is {c1, c2, …, c k}, the target text information is X = {x1, x2, ..., x n This embodiment generates target text information based on the coded information, the information to be processed and the emotional attribute information, and can generate a more logical, dramatic and attractive text expression in the plot generation game, and the generated target text information has emotional attributes, so that the generated target text information is more in line with the development of the plot, and the fluency, coherence and interest of the generated text are enhanced, and the immersive game experience of the game players is improved.

[0103] In a specific implementation, step S30 includes:

[0104] Step S31, fusing the information to be processed and the emotional attribute information to obtain first fused information;

[0105] Step S32: Decode the first fused information and the first encoded information to obtain target text information.

[0106] The first fusion information is the fusion information obtained by fusing the information to be processed and the emotional attribute information. The first fusion information can be expressed as X d1=concat(L1,C), where X d1 represents the first fused information, L1 represents the emotional attribute information, and C represents the information to be processed. When the first coded information, the information to be processed, and the emotional attribute information are decoded in this embodiment, the information to be processed and the emotional attribute information are first fused to obtain the first fused information, and then the first fused information and the first coded information are decoded to obtain the target text information.

[0107] In a specific implementation, continue to refer to Figure 2 As shown, the text generation model also includes a decoder, and the step of decoding the first fusion information and the first encoding information may specifically include: inputting the first fusion information and the first encoding information into the decoder, and decoding the first fusion information and the first encoding information through the decoder to obtain the target text information.

[0108] In a specific implementation, step S32 includes:

[0109] Step S321, determining second coding information based on the first coding information;

[0110] Step S322, normalizing the second encoded information to obtain attention information;

[0111] Step S323, determining third encoding information based on the attention information and the first encoding information;

[0112] Step S324: Decode the third coded information and the first fused information to obtain decoded information;

[0113] Step S325, mapping the decoded information to obtain word distribution information;

[0114] Step S326: Determine the target text information based on the word distribution information.

[0115] The second coded information is the processed first coded information obtained by processing the first coded information based on the hidden state information of the decoder. The determination process of the second coded information can be expressed as: Among them, e t,i represents the second encoding information of the i-th word at time t, r i ∈R represents the encoding vector representation of the i-th word, s t-1 represents the hidden state information of the decoder at time t-1, W a represents a learnable parameter.

[0116] The attention information is the second encoded information after normalization. The determination process of the attention information can be expressed as: a t,irepresents the attention information of the i-th word at the t-th time, e t,i represents the second encoding information of the i-th word at time t, e t,j represents the second encoding information of the jth word at the tth time, and n represents the number of words in the first encoding information R.

[0117] The third encoding information is encoding information determined based on the attention information and the first encoding information. The determination process of the third encoding information can be expressed as: c t represents the third coded information at time t, a t,i represents the attention information of the i-th word at the t-th time, r i ∈R represents the encoding vector representation of the i-th word, and n represents the number of words in the first encoding information R.

[0118] After the third coded information is determined, the third coded information and the first fused information are decoded to obtain decoded information. The process of determining the decoded information can be expressed as: t =Decoder(y t-1 ,s t-1 ,c t , X d1 ), s t represents the decoded information at time t, s t-1 represents the decoding information at time t-1, c t represents the third coded information at time t, y t-1 represents the word predicted at time t-1, X d1 Represents the first fusion information.

[0119] After the decoded information is obtained, the decoded information is mapped using a preset third activation function to obtain word distribution information, and the target text information can be determined based on the word distribution information. The third activation function can be set as needed. For example, when the third activation function uses a softmax function, the process of determining the word distribution information can be expressed as: vocab =softmax(W k s t ), P vocab represents the word distribution information at time t, s t represents the decoded information at time t, W k represents the learnable weight matrix.

[0120] In a specific implementation, before step S20, the following steps are included:

[0121] Step S41, obtaining a training text set, wherein the training text set includes training texts;

[0122] Step S42: extracting sentiment from the training text to obtain aspect sentiment information of the training text; the aspect sentiment information includes attribute information, sentiment information and viewpoint information;

[0123] Step S43: determining the emotion label information of the training text based on the emotion information;

[0124] Step S44, masking the training text based on the sentiment tag information to obtain a masked text of the training text;

[0125] Step S45, fusing the mask text and the sentiment label information to obtain second fusion information;

[0126] Step S46: training the preset network model based on the training text, attribute information, viewpoint information and the second fusion information to obtain a text generation model.

[0127] The aforementioned steps mentioned that the text generation method is applied to the text generation model. Therefore, before step S20, a text generation model needs to be generated. The training text set is a pre-set text data set for generating a text generation model. The training text set includes training text. The training text can be a sentence or a paragraph input by a user through a computer device (for example, a smart phone), or a sentence or a paragraph obtained by converting the collected user conversation into text through a computer device. For example, the training text can be represented as X = {x1, x2, ..., x n}, x n Represents the nth word in the training text.

[0128] The preset network model is a pre-set network model. By training the preset network model with a training text set, a text generation model can be obtained. The structure of the preset network model is the same as that of the text generation model, that is, the preset network model also includes an encoder and a decoder. The difference between the preset network model and the text generation model is that the model parameters of the preset network model are the initial model parameters, and the model parameters of the text generation model are the trained model parameters.

[0129] Aspect sentiment information is the aspect sentiment triple information of the training text, which can be obtained from the training text by extracting aspect words and sentiment words through the sentiment triple extraction model. Aspect sentiment information contains one or more aspect sentiment triples, which can be expressed as W = {w1, w2, ..., w t}, W represents aspect sentiment information, w tRepresents the tth aspect sentiment triple. For example, assuming the training text is “X={She likes playing the guiter but hates singing songs}”, the aspect sentiment information W={w1,w2} can be extracted, where w1=[She,positive,likes playing the guiter], w2=[She,negative,hates singing songs].

[0130] Each aspect emotion triple in the aspect emotion information includes attribute information, emotion information and opinion information. The aspect emotion triple can be expressed as w i =[a i ,s i ,o i ],w i represents the i-th aspect sentiment triple, a i represents the attribute information of the i-th aspect sentiment triplet, s i represents the sentiment information of the i-th sentiment triplet, o i Represents the opinion information of the i-th aspect sentiment triple. For example, for w1 = [She, positive, likes playing the guiter], “She” represents attribute information, “positive” represents sentiment information, and “likes playing the guiter” represents opinion information; for w2 = [She, negative, hates singing songs], “She” represents attribute information, “negative” represents sentiment information, and “hates singing songs” represents opinion information.

[0131] The sentiment label information is the text sentiment label of the training text constructed based on the sentiment information in the aspect sentiment information. The sentiment label information includes the sentiment label corresponding to each word in the training text. The sentiment label information can be expressed as: L2 = {l1, l2, …, l n}, l n Represents the sentiment label of the nth word in the training text. For example, for the training text “X={Shelikes playing the guiter but hates singing songs}”, based on the sentiment information in the aspect sentiment information, the sentiment label information L2={0,0,2,2,2,2,0,1,1,1,0} can be determined, where 2 indicates that the sentiment attribute category of the word is positive, 1 indicates that the sentiment attribute category of the word is negative, the first and last 0s indicate the start and end symbols, and the 0s in other positions indicate that the sentiment attribute category of the word is neutral.

[0132] The masked text is text information obtained by masking the training text based on the emotion label information. After obtaining the emotion label information, this embodiment randomly masks the words with emotion attributes in the training text to obtain the masked text. For example, the emotion label of positive emotion is 2, the emotion label of negative emotion is 1, and the emotion label of neutral emotion is 0. When performing the masking process, the words corresponding to the non-zero positions of the emotion label in the training text are randomly masked to form the masked text. The masked text can be represented as X m ={ <s>x1,x2, <mask> x3, <mask><h2 style=";text-align:left;direction:ltr">,x5,…,x<h2 style=";text-align:left;direction:ltr"> n <h2 style=";text-align:left;direction:ltr"> <s>}, for example, the training text "X = {She likes playing the guitar but hates singing songs}" is masked to obtain the masked text X m ={ <s>She <mask> <mask>the guiter but hates <mask>songs <s>}.

[0133] The second fusion information is the fusion information obtained by fusing the mask text and the sentiment label information. The second fusion information can be expressed as: d2 =concat(L2,X m ), X d2 represents the second fusion information, L2 represents the emotional label information, X m Represents masked text.

[0134] The preset network model mentioned in the previous steps includes an encoder and a decoder. Figure 2 As shown, the steps of training the preset network model based on the training text, attribute information, viewpoint information and the second fusion information specifically include: inputting the training text, attribute information and viewpoint information into the encoder, determining the keyword information of the training text based on the training text, attribute information and viewpoint information through the encoder, and encoding the keyword information to obtain the fourth encoding information of the training text; inputting the fourth encoding information and the second fusion information into the decoder, and decoding the fourth encoding information and the second fusion information through the decoder to obtain the probability of each word in the training text; determining the loss value based on the probability and the loss function of the preset network model; when the loss value does not meet the preset conditions, correcting the model parameters of the preset network model based on the preset parameter learning rate, and continuing to execute the step of inputting the training text, attribute information and viewpoint information into the encoder until the loss value meets the preset conditions to obtain the text generation model. Among them, the calculation formula of the loss value is: Among them, L decoder represents the loss value, X m represents the mask text of the training text, L2 represents the emotional attribute information of the training text, and y t represents the tth word in the training text, p(y t |X m ,L2) indicates that in X m and L2 under the condition y t The probability of , m represents the number of training texts, and n represents the number of words in the training texts.

[0135] In a specific implementation, the step of encoding the keyword information to obtain the fourth encoded information of the training text is the same as the step of encoding the information to be processed to obtain the first encoded information of the information to be processed. For details, please refer to the aforementioned step S20, and this application will not repeat them here.

[0136] Furthermore, the fourth encoded information and the second fused information are input into the decoder, and the steps of decoding the fourth encoded information and the second fused information through the decoder are the same as the steps of decoding the first fused information and the first encoded information. For details, please refer to the aforementioned step S30, and this application will not repeat them here.

[0137] In order to better implement the text generation method in the embodiment of the present application, based on the text generation method, the embodiment of the present application also provides a text generation device, such as Figure 3 As shown, the text generation device includes:

[0138] An information acquisition unit 610 is used to acquire information to be processed and emotional attribute information;

[0139] An information processing unit 620 is used to encode the information to be processed to obtain first coded information of the information to be processed;

[0140] The text generation unit 630 is used to decode the first coded information, the information to be processed and the emotional attribute information to obtain the target text information.

[0141] In an embodiment of the present application, the information to be processed is encoded to obtain first encoded information, and target text information is generated based on the first encoded information and the information to be processed. This can generate a more logical, dramatic and attractive text expression in the plot generation game. The target text information is generated based on the emotional attribute information, and text with emotional attributes can be generated, so that the generated target text information is more in line with the development of the plot, thereby enhancing the fluency, coherence and interest of the generated text, and improving the immersive gaming experience of game players.

[0142] In some embodiments of the present application, the information processing unit 620 is specifically used to:

[0143] Extract and fuse features of the information to be processed to obtain first fused feature information of the information to be processed;

[0144] Filtering the first fused feature information based on the information to be processed to obtain second fused feature information;

[0145] Based on the second fused feature information, first encoding information of the information to be processed is determined.

[0146] In some embodiments of the present application, the information processing unit 620 is further configured to:

[0147] Perform feature extraction on the information to be processed to obtain first state information of each word in the information to be processed and second state information of each word;

[0148] Fusing the first state information of each word with the second state information of each word to obtain fused state information of each word;

[0149] The fusion state information of each word and the fusion state information of the neighboring words corresponding to each word are concatenated to obtain the concatenated state information of each word;

[0150] A convolution operation is performed on the splicing state information to obtain first fusion feature information of the information to be processed.

[0151] In some embodiments of the present application, the information processing unit 620 is further configured to:

[0152] Perform a convolution operation on the information to be processed to obtain first feature information of the information to be processed;

[0153] fusing the first feature information and the first fused feature information to obtain third fused feature information;

[0154] Performing feature mapping on the third fused feature information to obtain fourth fused feature information;

[0155] The first fused feature information is filtered based on the fourth fused feature information to obtain second fused feature information.

[0156] In some embodiments of the present application, the information processing unit 620 is further configured to:

[0157] Based on the second fused feature information, determining the second feature information and the third feature information;

[0158] Performing feature extraction on the second feature information to obtain fourth feature information;

[0159] fusing the fourth feature information and the third feature information to obtain fifth fused feature information;

[0160] Performing feature mapping on the fifth fused feature information to obtain mapped feature information;

[0161] The mapped feature information and the second feature information are fused to obtain first coded information of the information to be processed.

[0162] In some embodiments of the present application, the text generation unit 630 is specifically used to:

[0163] The information to be processed and the emotional attribute information are fused to obtain first fused information;

[0164] The first fused information and the first encoded information are decoded to obtain target text information.

[0165] In some embodiments of the present application, the text generation unit 630 is further configured to:

[0166] Based on the first coding information, determining second coding information;

[0167] Normalize the second encoded information to obtain attention information;

[0168] Determining third encoding information based on the attention information and the first encoding information;

[0169] Decoding the third coded information and the first fused information to obtain decoded information;

[0170] Mapping the decoded information to obtain word distribution information;

[0171] Based on the word distribution information, the target text information is determined.

[0172] The embodiment of the present application further provides a computer device, which integrates any text generation device provided in the embodiment of the present application, and the computer device includes:

[0173] one or more processors;

[0174] Memory; and

[0175] One or more applications, wherein the one or more applications are stored in a memory and are configured to execute, by a processor, the steps of the text generation method in any of the above-mentioned text generation method embodiments.

[0176] The present application also provides a computer device that integrates any of the text generation devices provided in the present application. Figure 4 As shown, it shows a schematic diagram of the structure of the computer device involved in the embodiment of the present application, specifically:

[0177] The computer device may include one or more processing core processors 801, one or more computer-readable storage media memories 802, a power supply 803, an input unit 804 and other components. Those skilled in the art will appreciate that Figure 4 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:

[0178] The processor 801 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 802 and calling data stored in the memory 802, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 801.

[0179] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 802 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.

[0180] The computer device also includes a power supply 803 for supplying power to each component. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions. The power supply 803 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0181] The computer device may further include an input unit 804, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0182] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 801 in the computer device will load the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 will run the application programs stored in the memory 802, thereby realizing various functions, as follows:

[0183] Obtaining information to be processed and emotional attribute information;

[0184] Encoding the information to be processed to obtain first coded information of the information to be processed;

[0185] The first coded information, the information to be processed and the emotional attribute information are decoded to obtain the target text information.

[0186] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0187] To this end, the embodiment of the present application provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any text generation method provided in the embodiment of the present application. For example, the computer program is loaded by a processor to execute the following steps:

[0188] Obtaining information to be processed and emotional attribute information;

[0189] Encoding the information to be processed to obtain first coded information of the information to be processed;

[0190] The first coded information, the information to be processed and the emotional attribute information are decoded to obtain the target text information.

[0191] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.

[0192] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.

[0193] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0194] The above is a detailed introduction to a text generation method, device, computer equipment and computer-readable storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.< / s> < / mask> < / mask> < / mask> < / s> < / s> < / mask> < / mask> < / s>

Claims

1. A text generation method, characterized in that: include: Obtaining information to be processed and emotional attribute information; Encoding the information to be processed to obtain first coded information of the information to be processed; The first coded information, the information to be processed and the emotional attribute information are decoded to obtain target text information.

2. The method according to claim 1, characterized in that The encoding process of the information to be processed to obtain first encoded information of the information to be processed includes: Extracting and fusing features of the information to be processed to obtain first fused feature information of the information to be processed; Filtering the first fused feature information based on the information to be processed to obtain second fused feature information; Based on the second fused feature information, first encoding information of the information to be processed is determined.

3. The method according to claim 2, characterized in that The extracting and fusing the features of the information to be processed to obtain first fused feature information of the information to be processed includes: Performing feature extraction on the information to be processed to obtain first state information of each word and second state information of each word in the information to be processed; fusing the first state information of each word with the second state information of each word to obtain fused state information of each word; The fusion state information of each word and the fusion state information of the neighboring words corresponding to each word are concatenated to obtain the concatenated state information of each word; A convolution operation is performed on the splicing state information to obtain first fusion feature information of the information to be processed.

4. The method according to claim 2, characterized in that: The filtering the first fused feature information based on the information to be processed to obtain second fused feature information includes: Performing a convolution operation on the information to be processed to obtain first feature information of the information to be processed; fusing the first feature information and the first fused feature information to obtain third fused feature information; Performing feature mapping on the third fused feature information to obtain fourth fused feature information; The first fused feature information is filtered based on the fourth fused feature information to obtain second fused feature information.

5. The method according to claim 2, characterized in that: The determining, based on the second fusion feature information, first encoding information of the information to be processed includes: Determining second feature information and third feature information based on the second fused feature information; performing feature extraction on the second feature information to obtain fourth feature information; fusing the fourth feature information and the third feature information to obtain fifth fused feature information; Performing feature mapping on the fifth fused feature information to obtain mapped feature information; The mapping feature information and the second feature information are merged to obtain first encoding information of the information to be processed.

6. The method according to claim 1, characterized in that The decoding process of the first coded information, the information to be processed and the emotional attribute information to obtain target text information includes: Fusing the information to be processed and the emotional attribute information to obtain first fused information; The first fused information and the first encoded information are decoded to obtain target text information.

7. The method according to claim 6, characterized in that The decoding process of the first fused information and the first encoded information to obtain target text information includes: Determine second encoding information based on the first encoding information; Normalizing the second encoded information to obtain attention information; Determining third encoding information based on the attention information and the first encoding information; Decoding the third coded information and the first fused information to obtain decoded information; Performing mapping processing on the decoded information to obtain word distribution information; Based on the word distribution information, target text information is determined.

8. A text generation device, characterized in that: include: An information acquisition unit, used to acquire information to be processed and emotional attribute information; An information processing unit, configured to encode the information to be processed to obtain first encoded information of the information to be processed; The text generation unit is used to decode the first coded information, the information to be processed and the emotional attribute information to obtain target text information.

9. A computer device, characterized in that: The computer device comprises: one or more processors; Memory; and One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the text generation method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in the text generation method according to any one of claims 1 to 7.