Text generation method and device, text interaction method and device, equipment and storage medium
By constructing a training set and using a text generation model to convert the logically strong text in the game into natural language, combined with the reward mechanism of the reinforcement learning agent, the problem of insufficient language in the output text of the agent is solved, and style controllability and natural language are achieved Expression improves the interactive experience of the game.
Patent Information
- Application Number
- CN202310187491.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-23
- Publication Date
- 2024-08-23
AI Technical Summary
When reinforcement learning is applied to role-playing games, the text actions output by the agent are highly logical but weak in language. It is difficult to convert them into natural language expression habits and lacks the ability to control style.
By constructing a training set and using a text generation model and a text parsing model, the input text is converted into an output text with a predetermined style that is more in line with natural language expression habits. The model is updated based on the reward mechanism of the reinforcement learning agent to achieve text with controllable style. generate.
It improves the interactive experience of reinforcement learning agents in role-playing games, ensures that the output text style is controllable, conforms to natural language expression habits, and enhances the naturalness of interaction with real players.
Smart Images

Figure CN118536492A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of text processing, and in particular to a text generation method, a text interaction method, a device, a equipment and a storage medium. Background Art
[0002] When applying reinforcement learning to role-playing board games that involve complex logical reasoning and open text interaction (such as Werewolf), it can be further abstracted into natural language processing, logical reasoning, and decision-making problems in vertical fields.
[0003] In role-playing games based on reinforcement learning, the action space of the agent contains text outputs. The text in the action space of the reinforcement learning agent is usually logical text with strong logic but weak linguistic properties. In order to improve the interactive experience, the text actions selected by the reinforcement learning agent need to be converted into text that is more in line with natural language expression habits.
[0004] However, when converting the text actions selected by the reinforcement learning agent into text that is more in line with natural language expression habits, how to control the style of the converted text so that the speaking style of the reinforcement learning agent can be controlled is a technical problem that urgently needs to be solved. Summary of the invention
[0005] A technical problem to be solved by the present disclosure is how to design a text conversion solution with controllable style.
[0006] According to a first aspect of the present disclosure, a text generation method is provided, comprising: constructing a training set based on multiple first texts corresponding to the same style type and second texts corresponding to the first texts, wherein the second text is used to characterize the sentence trunk logic of the first text; and training a text generation model using the training set, wherein the text generation model is used to process the input text to obtain an output text having a predetermined style and being more in line with natural language expression habits than the input text.
[0007] Optionally, the first text is an unlabeled text that conforms to natural language expression habits, and the method further includes: predicting the style type of the first text using a style classification model; and parsing the first text using a text parsing model to obtain a second text corresponding to the first text.
[0008] Optionally, the method further includes: generating a fourth text corresponding to the third text using a text generation model; and training a text parsing model based on the third text and the fourth text.
[0009] Optionally, the method involves multiple participants, at least one of the multiple participants is a reinforcement learning agent, and the method also includes: using the text selected by the reinforcement learning agent from the action space based on the state in the state space as the third text, and using the fourth text as the text output by the reinforcement learning agent in the current round; using the text output by other participants as the first text, and using the second text as the state in the state space of the reinforcement learning agent.
[0010] Optionally, the method also includes: using the rewards obtained by the reinforcement learning agent during the training process as feedback to the text generation model and / or the text parsing model, and updating the text generation model and / or the text parsing model based on the feedback.
[0011] Optionally, the participants are players in a role-playing game who advance the game through actions and text expressions, the action space of the reinforcement learning agent includes exclusive actions, speech texts, and public actions, and the state space of the reinforcement learning agent includes attribute states, basic states, and observation states.
[0012] According to a second aspect of the present disclosure, a reinforcement learning-based text interaction method is provided, the method involving multiple participants, at least one of the multiple participants being a reinforcement learning agent, the method comprising: selecting a text generation model consistent with a target speech style from multiple text generation models, wherein the text generation model is used to process an input text to obtain an output text that matches a style type corresponding to the text generation model, and the output text is more in line with natural language expression habits than the input text; if during any round of interaction, an action selected by the reinforcement learning agent from an action space based on a state in a state space includes a fifth text, then a sixth text corresponding to the fifth text is generated using the selected text generation model, and the sixth text is used as the text output by the reinforcement learning agent in the current round.
[0013] Optionally, the method further includes: determining a style type of a speech text output by a target participant, wherein the target participant is a real person user; and providing the determined style type to the target participant.
[0014] Optionally, the method also includes: parsing the speech text output by the target participant to obtain a logical text for representing the sentence trunk logic of the speech text; and training a text generation model for simulating the target participant's speaking style based on the speech text and the logical text output by the target participant.
[0015] According to a third aspect of the present disclosure, a text generation device is provided, comprising: a construction module for constructing a training set based on multiple first texts corresponding to the same style type and a second text corresponding to the first text, wherein the second text is used to characterize the sentence trunk logic of the first text; a training module for training a text generation model using the training set, wherein the text generation model is used to process the input text to obtain an output text having a predetermined style and being more in line with natural language expression habits than the input text.
[0016] Optionally, the first text is an unlabeled text that conforms to natural language expression habits, and the device also includes: a prediction module, used to predict the style type of the first text using a style classification model; and a parsing module, used to parse the first text using a text parsing model to obtain a second text corresponding to the first text.
[0017] Optionally, the device further includes: a generation module, configured to generate a fourth text corresponding to the third text using a text generation model, and the training module further trains a text parsing model based on the third text and the fourth text.
[0018] Optionally, the device is used in a text interaction scenario involving multiple participants, at least one of the multiple participants is a reinforcement learning agent, and the device also includes: a first processing module, used to use the text selected by the reinforcement learning agent from the action space based on the state in the state space as the third text, and use the fourth text as the text output by the reinforcement learning agent in the current round; a second processing module, used to use the text output by other participants as the first text, and use the second text as the state in the state space of the reinforcement learning agent.
[0019] Optionally, the training module uses the rewards obtained by the reinforcement learning agent during the training process as feedback to the text generation model and / or the text parsing model, and updates the text generation model and / or the text parsing model based on the feedback.
[0020] Optionally, the participants are players in a role-playing game who advance the game through actions and text expressions, the action space of the reinforcement learning agent includes exclusive actions, speech texts, and public actions, and the state space of the reinforcement learning agent includes attribute states, basic states, and observation states.
[0021] According to a fourth aspect of the present disclosure, a text interaction device based on reinforcement learning is provided, the device being used in a text interaction scenario involving multiple participants, at least one of the multiple participants being a reinforcement learning agent, the device comprising: a selection module for selecting a text generation model consistent with a target speech style from multiple text generation models, wherein the text generation model is used to process an input text to obtain an output text that matches a style type corresponding to the text generation model, and the output text is more in line with natural language expression habits than the input text; a processing module for generating a sixth text corresponding to the fifth text using the selected text generation model if the action selected by the reinforcement learning agent from the action space based on the state in the state space during any round of interaction includes a fifth text, and using the sixth text as the text output by the reinforcement learning agent in the current round.
[0022] Optionally, the device further comprises: a determination module for determining the style type of the speech text output by the target participant, wherein the target participant is a real person user; and a providing module for providing the determined style type to the target participant.
[0023] Optionally, the device also includes: a parsing module, used to parse the speech text output by the target participant to obtain a logical text for representing the sentence trunk logic of the speech text; a training module, used to train a text generation model for simulating the speaking style of the target participant based on the speech text and the logical text output by the target participant.
[0024] According to a fifth aspect of the present disclosure, a computing device is provided, comprising: a processor; and a memory on which executable code is stored, and when the executable code is executed by the processor, the processor executes the method described in the first aspect or the second aspect above.
[0025] According to a sixth aspect of the present disclosure, a computer program product is provided, comprising an executable code. When the executable code is executed by a processor of an electronic device, the processor is caused to execute the method described in the first aspect or the second aspect above.
[0026] According to the seventh aspect of the present disclosure, a non-temporary machine-readable storage medium is provided, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the method described in the first aspect or the second aspect above.
[0027] Therefore, the present disclosure constructs a training set based on multiple first texts corresponding to the same style type and second texts corresponding to the first texts, and trains a text generation model based on the training set, so that the output text generated by the generated text generation model for the input text has a predetermined style. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.
[0029] Figure 1 A schematic flowchart of a text generation method according to an embodiment of the present disclosure is shown.
[0030] Figure 2 A schematic diagram of the overall process of a role-playing game based on reinforcement learning is shown.
[0031] Figure 3 A schematic diagram of the training process of the style classification model is shown.
[0032] Figure 4 The process of training a text generation model based on unlabeled free text is shown.
[0033] Figure 5 A schematic structural diagram of a text generation device according to an embodiment of the present disclosure is shown.
[0034] Figure 6 A structural schematic diagram of a text interaction device according to an embodiment of the present disclosure is shown.
[0035] Figure 7 A schematic diagram of the structure of a computing device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0036] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0037] The reinforcement learning agent described in the present disclosure is used in application scenarios involving text interaction.
[0038] Application scenarios involving text interaction can be role-playing games that advance the game process based on interactive text, such as but not limited to role-playing board games such as "Werewolf", "Close Your Eyes Before Dark", and "Avalon". Such games usually require multiple players to play multiple roles, and players advance the game process through actions and text expressions. For such role-playing games, one or more reinforcement learning agents can be trained using reinforcement learning algorithms. Different reinforcement learning agents can be trained for different roles. The same role can share the same reinforcement learning agent. During the process of training the reinforcement learning agent or after the reinforcement learning agent is trained, the reinforcement learning agent can play games with real players.
[0039] Application scenarios involving text interaction can also be other application scenarios that require human-computer dialogue. For example, service personnel in the service industry (such as sales personnel, customer service personnel, fund managers, etc.) need to communicate frequently with customers. In order to improve the communication skills of service personnel, reinforcement learning algorithms can be used to train intelligent training robots (i.e., reinforcement learning agents) that can simulate customers. Service personnel can improve their communication skills by talking with intelligent training robots.
[0040] There are multiple (at least two) participants in the application scenario involving text interaction. At least one of the multiple participants is a reinforcement learning agent. Multiple participants can achieve a predetermined goal through one or more rounds of interaction, such as multiple players can continuously interact based on text and behavior until the game ends. Among them, the reinforcement learning agent can generate actions in the action space based on the state in the state space, and the action updates the state in the state space after interacting with the environment.
[0041] A reinforcement learning agent can be an agent trained using a reinforcement learning algorithm. The reinforcement learning algorithm can be any of a value function-based method, a policy-based method, and an actor-critic method (Actor-Critic algorithm). As an example, a reinforcement learning agent can be learned using a PPO algorithm or an improved algorithm based on the PPO algorithm (such as an IPPO algorithm or a MAPPO algorithm). The PPO (Proximal Policy Optimization) algorithm has two network structures, a policy network (Actor network) and an evaluation network (Critic network). The input of the Actor network is the state, and the output is the action probability. The input of the Critic network is the state, and the output is the value of the state. The problem solved by the PPO algorithm is the reinforcement learning problem in discrete action space and continuous action space.
[0042] The reinforcement learning algorithm used by the reinforcement learning agent and the process of using the reinforcement learning algorithm to train the reinforcement learning agent are both mature technologies in the field and will not be described in detail in this disclosure.
[0043] Unlike general reinforcement learning tasks, the action space and state space of the reinforcement learning agent in the present disclosure contain text output and text input, respectively. The text in the action space of the reinforcement learning agent is usually a logical text with strong logic but weak language. In order to improve the interactive experience, it is necessary to convert the text action (i.e., logical text) selected by the reinforcement learning agent into a text (i.e., free text) that is more in line with the natural language expression habits. At the same time, the text output by other participants in the environment can be perceived by the reinforcement learning agent, thereby affecting the action selected by the reinforcement learning agent in the next round. Therefore, it is also necessary to parse the text output by other participants in the environment into a state in the state space of the reinforcement learning agent.
[0044] The action space is used to characterize the set of actions that the reinforcement learning agent can choose. The actions in the action space of the reinforcement learning agent include text actions and optionally behavioral actions. That is, the actions in the action space of the reinforcement learning agent can be divided into two categories: text actions and behavioral actions. Text actions refer to actions taken by the reinforcement learning agent in the form of output text, and the text output by the reinforcement learning agent can be perceived by other participants. Therefore, the text output by the reinforcement learning agent can also be called speech text. Behavioral actions refer to actions in non-text form. The behavioral actions output by the reinforcement learning agent can implicitly or explicitly affect other participants.
[0045] When designing the action space of a reinforcement learning agent, the action space can be designed based on the role played by the reinforcement learning agent, the purpose the role expects to achieve, the functions the role has, and other information. Taking the "Werewolf" game as an example, the identity of the reinforcement learning agent playing the player can be, but is not limited to, any of "werewolf", "witch", "villager", "prophet", and "guard". The actions in the action space can be divided into exclusive actions, speech texts, and public actions. Exclusive actions refer to actions that are bound to a specific identity and can only be performed by players with that identity (for example, exclusive actions for witches can include poisoning and saving people). Exclusive actions themselves may be open to other participants, or they may not be open to other participants but directly interact with the environment, implicitly affecting other players or agents. Speech text refers to the logic expressed by the agent based on the state space and the purpose of the game. Public actions refer to actions that all participants have and have the same process. Public actions can be open to all players, that is, public actions can be perceived by all players, such as voting.
[0046] The state space is used to represent the set of states observed by the reinforcement learning agent from the environment. During the continuous interaction between the reinforcement learning agent and the environment, the reinforcement learning agent can observe different states. The states in the state space can be the latest observed states. The states in the state space can include states that do not change after initialization, as well as states that change in real time based on the actions output by other participants during the interaction.
[0047] Taking role-playing games such as "Werewolf" as an example, the states in the state space of reinforcement learning agents can be divided into attribute states, basic states, and observation states. Attribute states are used to represent attribute information that does not change after the game starts (for example, it can include the role information of the agent and the role information of other participants that the agent can perceive), basic states are used to represent observation information that can be changed and determined during the game (such as the survival status of participants), and observation states are used to represent reasoning information generated based on the speech texts and / or actions of other players.
[0048] When converting the text actions selected by the reinforcement learning agent into text that is more in line with natural language expression habits as the text output by the reinforcement learning agent, in order to enable the reinforcement learning agent to output text that conforms to the expected style, it is necessary to design a style-controllable text generation scheme.
[0049] Figure 1 A schematic flowchart of a text generation method according to an embodiment of the present disclosure is shown.
[0050] See also Figure 1 In step S110, a training set is constructed based on a plurality of first texts corresponding to the same style type and a second text corresponding to the first text.
[0051] The first text has the same semantics as the second text, and the first text is more in line with natural language expression habits than the second text. For example, the second text can be a text used to characterize the sentence trunk logic of the first text. In other words, the first text can be regarded as a text that conforms to natural language expression habits. The second text can be regarded as the sentence trunk obtained by logically extracting the first text, that is, the second text can be regarded as the content summary of the first text.
[0052] For example, the first text can be "After watching this round, I think it is very likely that player 2 is not a good person", or "player 2 is definitely a wolf, my judgment is not wrong, everyone follow me and vote out player 2!" Such free texts are more in line with natural language expression. The second text can be the logical text "player 2 is a werewolf" obtained by extracting the main logic of the sentence in the first text.
[0053] The second text can be regarded as the annotation result of the first text. A first text and the second text corresponding to the first text can constitute a training data in the training set.
[0054] The style type represents the speaking style of the first text. Different style types can represent different speaking styles. The first texts corresponding to different style types and the second texts corresponding to the first texts can be divided into different training sets, so that all training data in the same training set correspond to the same style type.
[0055] Style types can be divided based on, but not limited to, the intensity of expression (whether the text expressing opinions is more intense), the degree of love of expression (whether the text expressing opinions is richer, the sentences are longer or more concise), the degree of ambiguity in expressing opinions (whether to express opinions more clearly or more vaguely and obscurely), the degree of doubting others (whether the text expressing opinions is more inclined to doubt others and uncertain about one's own opinions), and other characteristic dimensions that can characterize the speaking style. Different style types have different characteristic values under the same characteristic dimension.
[0056] The style space can be defined according to the actual application scenario so that the style type in the style space is adapted to the actual application scenario. Different style types in the style space can be as independent of each other as possible, while satisfying the description of a vague abstract concept. Taking the Werewolf game scene as an example, one or more style types can be set for different characters, that is, the style type can characterize the speaking style of a specific character. For example, style types may include but are not limited to fools (villager characters who cannot see the situation clearly and speak randomly), mobs (villager characters who disrupt the situation through speech or behavior), deep-water wolves (wolf characters who never reveal their identities and pretend to be civilians), and hook wolves (wolf characters who sell their teammates to make their identities known).
[0057] In step S120, the text generation model is trained using the training set.
[0058] As described above, a first text and a second text corresponding to the first text can constitute a training data. The training data can be used to train a text generation model. Among them, the second text can be used as the input of the text generation model, and the first text can be regarded as the annotation result of the second text. The text generation model can be trained with the purpose of making the output obtained by the text generation model processing the second text as close to the first text as possible. The specific training process is a mature technology in this field. For example, a loss function can be constructed based on the difference between the output of the text generation model and the first text, so that the loss function is reduced to the target training text parsing model. Among them, when constructing the loss function, indicators such as the sentence length of the model output, the degree to which the model output conforms to the natural language expression habits, and the reward from reinforcement learning (when combining model training with the agent training process) can also be considered.
[0059] The text generation model can adopt a generative model structure in which both the model input and the model output are text, such as a Seq2Seq model based on an encoder-decoder architecture. The text generation model can include an encoder and a decoder, the encoder is used to encode the input text, and the decoder is used to decode the encoding result to obtain the output text. The model structure of the text generation model is a mature technology in the field, and this disclosure will not be repeated.
[0060] In order to solve the cold start problem, the text generation model can use a general domain pre-trained model (such as GPT-3), so that only a small amount of training data in the specific application scenario needs to be used to fine-tune the pre-trained model, without the need to retrain the model. A pre-trained model refers to a model that has been pre-trained using general domain data. For the sake of distinction, the pre-trained model used by the text generation model can be called the first pre-trained model.
[0061] The text generation model is used to process the input text to obtain an output text with a predetermined style and more in line with the natural language expression habits than the input text. Since all the sample data in the training set correspond to the same style type. Therefore, the style of the text generated by the text generation model trained with the training set is consistent with the style type corresponding to the sample data in the training set. Therefore, by training the text generation model with sample data corresponding to the same style, the style of the text output by the text generation model can be controlled. Among them, different text generation models can be trained using training sets corresponding to different style types to obtain text generation models corresponding to different style types.
[0062] In the present disclosure, the first text may be an unlabeled text that conforms to the natural language expression habits. That is, the style type of the first text is unknown, and the second text corresponding to the first text is unknown. In order to construct a training set, the style type of the first text may be determined, and the first text may be parsed to obtain the second text corresponding to the first text.
[0063] The style type of the first text may be determined manually. For example, a labeling task for labeling the style type of the first text may be generated, and the labeling task may be sent to a labeler, who then labels the style type of the first text.
[0064] The style type of the first text can also be predicted using an easily trainable style classification model. The style classification model can be viewed as a binary classification model that can estimate multiple style types. The style classification model can view each style type as a binary classification problem and perform multi-objective learning by using cross entropy loss (binary loss).
[0065] The first text may be manually parsed to obtain a second text corresponding to the first text. For example, a task may be generated to extract the sentence stems of the first text, and the task may be assigned to relevant personnel, and the sentence stems extracted by the relevant personnel may be used as the second text corresponding to the first text.
[0066] The first text may also be used as an input of a text parsing model to obtain a second text output by the text parsing model.
[0067] The text parsing model is used to parse the target text and obtain a logical text that is used to characterize the sentence trunk logic of the target text. The target text may refer to a text that conforms to the natural language expression habits. The text parsing model may adopt a generative model structure in which both the model input and the model output are texts, such as a Seq2Seq model based on an encoder-decoder architecture. That is, the text parsing model may include an encoder and a decoder, the encoder is used to encode the input text, and the decoder is used to decode the encoding result to obtain the output text. The encoder may adopt a BERT model structure. The output of the decoder may be a sequence of labels that constitute the sentence trunk.
[0068] The text generation model is used to convert logical text with strong logic into more natural free text, and the text parsing model is used to convert free text into logical text. Since the input and output of the text generation model and the text parsing model are exactly opposite, during the training process, the text generation model and the text parsing model can provide training data for each other.
[0069] Specifically, a fourth text corresponding to the third text may also be generated using a text generation model.
[0070] The fourth text has the same semantics as the third text, and the fourth text is more in line with natural language expression habits than the third text. The third text can be a logical text with strong logic and weak linguistics. The fourth text can be regarded as a text obtained by expanding the first text based on the semantics represented by the first text.
[0071] A first text and a second text corresponding to the first text can constitute a training data. The training data can be used to train a text parsing model. Therefore, the text parsing model can be trained based on the third text and the fourth text. Among them, the fourth text is the input of the text parsing model, and the third text can be regarded as the annotation result of the fourth text. The text parsing model can be trained with the purpose of making the output obtained by the text parsing model parsing the fourth text as close to the third text as possible. The specific training process is a mature technology in this field. For example, a loss function can be constructed based on the difference between the output of the text parsing model and the third text, so that the loss function is reduced to the target training text parsing model. Among them, when constructing the loss function, indicators such as the sentence length of the model output, the ease of sentence parsing, and the reward from reinforcement learning (when combining model training with the agent training process) can also be considered.
[0072] In order to solve the cold start problem, the text parsing model can also use a pre-trained model in a general domain. Therefore, it is only necessary to fine-tune the pre-trained model using sample data in the domain where the reinforcement learning agent is located, without having to retrain the model. A pre-trained model refers to a model that has been pre-trained using general domain data. For the sake of distinction, the pre-trained model used by the text parsing model can be called the second pre-trained model.
[0073] In addition to training the text parsing model using the training data provided by the text generation model (i.e., the first text and the second text corresponding to the first text), a small amount of vertical field dialogue text can be obtained from open source channels, and the dialogue text can be annotated and data enhanced to obtain training data that can be used to fine-tune the second pre-trained model (for ease of distinction, it can be referred to as the second training data). The second pre-trained model can be fine-tuned using the pre-acquired second training data to obtain a text parsing model that has been preliminarily trained. A second training data can be composed of a dialogue text and a logical text obtained by parsing the dialogue text to characterize the sentence trunk logic of the dialogue text. The dialogue text can be used as the input of the text parsing model, and the text parsing model can be fine-tuned with the purpose of making the output of the text parsing model as close to the logical text as possible. The specific training process is a mature technology in this field. For example, a loss function can be constructed based on the difference between the output of the text parsing model and the logical text, so that the loss function is reduced to the target training text parsing model.
[0074] By designing a text generation model and a text parsing model that are dual tasks to each other, the text generation model and the text parsing model can provide each other with training data during the training process, thereby solving the problem of insufficient training data in vertical fields.
[0075] For text parsing models, since the labels of training data are logical texts, annotation is more complicated; and for text generation models, it is difficult to ensure the diversity of output in the training corpus. To this end, the present disclosure proposes that training labels and data references can be provided for text parsing models and text generation models based on the text interaction process (training process or application process) of reinforcement learning agents.
[0076] In other words, the training process for the text generation model and the text parsing model can be placed in the text interaction process based on the reinforcement learning agent, so as to utilize the large amount of logical text corpus and text corpus that conforms to the natural language expression habits generated during the interaction between the reinforcement learning agent and the environment (such as other participants in the environment) to provide training data for the training of the text generation model and the text parsing model.
[0077] Specifically, the text selected by the reinforcement learning agent from the action space based on the state in the state space is a logical text with strong logic but poor linguistics. Therefore, the text selected by the reinforcement learning agent from the action space based on the state in the state space can be used as the input of the text generation model (i.e., the third text). In addition, the output (i.e., the fourth text) obtained by processing the first text by the text generation model can be used as the text output by the reinforcement learning agent in the current round (i.e., the speech text). Thus, while improving the interactive experience, the third text and the fourth text can be used as training corpus for the text parsing model.
[0078] During the interaction between the reinforcement learning agent and the environment, the text output by other participants (such as real players) is free text that conforms to the natural language expression habits. Therefore, the text output by other participants can be used as the input of the text parsing model and the style classification model (i.e., the first text) to obtain the second text corresponding to the first text and the style type of the first text. In addition, the output (i.e., the second text) obtained by the text parsing model processing the first text can be used as the state in the state space of the reinforcement learning agent. Thus, while meeting the text processing needs of the reinforcement learning agent, the first text and the second text that can be used as training corpus for the text generation model can be obtained. Among them, the first text and the second text that are consistent with the style type corresponding to the text generation model to be trained can be used as training corpus.
[0079] By placing the training process of the text generation model and the text parsing model in the text interaction process based on the reinforcement learning agent, it can not only meet the text processing needs of the reinforcement learning agent (that is, converting the text actions selected by the reinforcement learning agent into more natural speech text, and parsing the text output by other participants into states in the state space of the reinforcement learning agent), but also use the logical text corpus generated in the interaction process and the text corpus that conforms to the natural language expression habits to provide training data for the training of the text generation model and the text parsing model.
[0080] The text interaction process based on the reinforcement learning agent can refer to the training process of the reinforcement learning agent, or it can refer to the use process of the reinforcement learning agent after training. Taking the text interaction process based on the reinforcement learning agent as the training process of the reinforcement learning agent as an example, the reward obtained by the reinforcement learning agent during the training process can also be used as feedback for the text generation model and / or the text parsing model, and the text generation model and / or the text parsing model can be updated based on the feedback. In addition, other indicators that are relatively easy to obtain (such as sentence length, sentence parsing ease, etc.) can also be used as feedback for model training.
[0081] Based on the method described above, multiple text generation models corresponding to different style types can be obtained. The text generation model is used to process the input text to obtain output text that matches the style type corresponding to the text generation model. The output text is more in line with natural language expression habits than the input text.
[0082] When a text generation model is used in a text interaction process based on reinforcement learning, a text generation model that is consistent with the target speech style can be selected from multiple text generation models. If the action selected by the reinforcement learning agent from the action space based on the state in the state space during any round of interaction includes text (which can be called the fifth text for the sake of distinction), the selected text generation model can be used to generate a sixth text corresponding to the fifth text, and the sixth text can be used as the text output by the reinforcement learning agent in the current round. In this way, the speech style of the reinforcement learning agent can be controlled.
[0083] As an example, the behavior action output by the reinforcement learning agent can also be controlled based on the behavior style parameters of the reinforcement learning agent, so that the behavior action output by the reinforcement learning agent conforms to the behavior style parameters. Thus, the behavior style of the reinforcement learning agent can be controlled.
[0084] The present disclosure can also determine the style type of the speech text output by the target participant, such as using a style classification model to determine the style type of the speech text output by the target participant. The target participant can be a real player, and after obtaining the style type of the target participant, the determined style type can be provided to the target participant (such as in a visual manner). In this way, the interactive experience of the real player can be improved.
[0085] The present disclosure can also utilize a text parsing model to parse the speech text output by the target participant, and obtain a logical text for characterizing the sentence trunk logic of the speech text. Based on the speech text and logical text output by the target participant, a text generation model for simulating the target participant's speech style can be trained. The logical text can be used as the input of the text generation model, and the text generation model can be trained with the purpose of making the output of the text generation model as close to the speech text as possible. The trained text generation model can replicate the style of the target participant. By using the trained text generation model for a reinforcement learning agent, a virtual player can be obtained that is very similar to the player in terms of style and speech performance.
[0086] The following is an example of a role-playing game (such as Werewolf) that uses actions and text expressions to advance the game.
[0087] Figure 2 A schematic diagram of the overall process of a role-playing game based on reinforcement learning is shown.
[0088] See also Figure 2 , the reinforcement learning agent contains a state space and an action space, and the reinforcement learning agent interacts with the simulation simulator (environment). Specifically, the agent generates actions in the action space according to the specific state in the state space, and the action interacts with the simulation simulator to update the state in the state space.
[0089] Unlike other reinforcement learning tasks, the action space and state space of the agent in this embodiment contain text output and text input respectively. Therefore, it is necessary to use a text logic processor to parse the text in the action, and at the same time, parse the text in the state output by the simulation simulator into a specific state in the state space.
[0090] Usually the same character will use the same agent model. For example, there is only one model for the werewolf agent, but multiple players can have the werewolf identity in a game at the same time. In order to make the agent behave more like a real person during the interaction, the same type of agent needs to have different styles. Therefore, an additional personality style generator is needed. The personality style generator provides diversity in the performance of the same agent. The performance of different instances of the same agent can be achieved in the following two ways: 1. Initialization method: use different parameters when initializing each agent; 2. Post-processing method: each agent contains a certain action mask to lower or increase the probability of certain actions.
[0091] The random initialization method is uncontrollable, and the post-processing methods are not rich in diversity. At the same time, these two methods cannot be well migrated to the new style space. Therefore, this embodiment proposes to learn a style-controllable text generation model, and use the style-controllable text generation model to provide different outputs for each action of the intelligent agent from other intelligent agents.
[0092] Taking the Werewolf game as an example, for Werewolf agents of different styles that need to be trained, the process from state space to final action will be manifested in the following two processes: 1. The agent model uses the state space as input and obtains the action space as output; 2. The text generation model generates free text that is more in line with natural expression through the logical text part in the action space. This embodiment mainly improves the second process to obtain agents of different styles.
[0093] The overall process can be divided into five parts: definition of style space, fine-tuning of text parsing model, labeling and training of style classification model, training of controllable text generation model, and control and estimation of controllable style agent.
[0094] 1. Define the style space
[0095] The dimensions of the style space are as independent as possible, while being able to satisfy the description of a vague abstract concept, such as (mob: a player with a very irritable civilian role) and deep-water wolf (a player who never reveals his identity and pretends to be a civilian werewolf role). In this embodiment, the style space can be defined according to the following aspects: (1) the degree of doubt of others, that is, whether the expression is more inclined to doubt others and uncertain about one's own views; (2) the degree of expression, that is, whether the expression is richer, the sentences are longer or more concise; (3) the intensity of expression, that is, whether the expression of views is more intense; (4) the ambiguity of one's own views, that is, whether to express one's own views more clearly or more vaguely and obscurely.
[0096] 2. Fine-tuning of text parsing model
[0097] A small amount of Werewolf game dialogue text can be obtained from open source channels, annotated and data enhanced to obtain real and usable training data (i.e., the second training data mentioned above). The text parsing model is fine-tuned based on the real data. For details, please refer to the relevant description above.
[0098] 3. Training of style classification model
[0099] Based on the style space, it is relatively easy to annotate the speech text in the Werewolf game, and then train a binary classification model that can estimate multiple dimensions. The model structure is designed as follows: each dimension of the style space is regarded as a binary classification problem, and binary loss (cross entropy loss) is used for multi-objective learning.
[0100] Figure 3 A schematic diagram of the training process of the style classification model is shown.
[0101] See also Figure 3 The style classification model can use a pre-trained model, such as a multi-classification model trained based on general data. The Werewolf game dialogue text can be used as the model input, and the annotation results of the Werewolf game dialogue text (i.e., style type) can be used as sample labels to fine-tune the pre-trained model to obtain a usable style classification model.
[0102] 4. Style-controllable text generation model training
[0103] For data with annotated free text (with corresponding style and logical text), the text generation model can be trained directly.
[0104] Figure 4 The process of training a text generation model based on unlabeled free text is shown.
[0105] See also Figure 4 For free text (such as unlabeled text collected from other channels (such as online Werewolf videos), or text corpus generated by real players and reinforcement learning agents after playing games, we can first use the style classification model and text parsing model trained in the previous text to make estimates, obtain the style space and logical text respectively, and then train the text generation model.
[0106] 5. Estimation stage
[0107] For each instantiated agent in each game, the speaking style of the agent can be controlled by controlling the various parameters of the style space, thereby achieving control of the agent's style.
[0108] For players who have played multiple rounds of games with the intelligent agent, the player's style attributes can be extracted according to the style classification model. On the one hand, they can be visualized and presented to the player. On the other hand, the player's style can be replicated to obtain a virtual player who is very similar to the player in terms of style and speech performance.
[0109] The text generation method disclosed in the present invention may also be implemented as a text generation device. Figure 5 The structure diagram of the text generation device according to one embodiment of the present disclosure is shown. The functional units of the text generation device can be implemented by hardware, software, or a combination of hardware and software that implements the principles of the present disclosure. It can be understood by those skilled in the art that Figure 5 The functional units described can be combined or divided into sub-units to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional units described herein. The following is a brief description of the functional units that the text generation device can have and the operations that each functional unit can perform. For the details involved, please refer to the relevant description above, which will not be repeated here.
[0110] See also Figure 5 , the text generating device 500 may include a construction module 510 and a training module 520 .
[0111] The construction module 510 is used to construct a training set based on a plurality of first texts corresponding to the same style type and a second text corresponding to the first text, wherein the second text is used to characterize the sentence trunk logic of the first text. The training module 520 is used to train a text generation model using the training set, wherein the text generation model is used to process the input text to obtain an output text having a predetermined style and being more in line with the natural language expression habits than the input text.
[0112] The first text may be an unannotated text that conforms to the natural language expression habits. The text generation device 500 may also include a prediction module and a parsing module. The prediction module is used to predict the style type of the first text using a style classification model; the parsing module is used to parse the first text using a text parsing model to obtain a second text corresponding to the first text.
[0113] The text generation device 500 may further include a generation module. The generation module is used to generate a fourth text corresponding to the third text using a text generation model. The training module 520 may further train a text parsing model based on the third text and the fourth text.
[0114] The text generation device 500 can be used in a text interaction scenario involving multiple participants, at least one of the multiple participants being a reinforcement learning agent. The text generation device 500 may also include a first processing module and a second processing module. The first processing module is used to use the text selected by the reinforcement learning agent from the action space based on the state in the state space as the third text, and use the fourth text as the text output by the reinforcement learning agent in the current round. The second processing module is used to use the text output by other participants as the first text, and use the second text as the state in the state space of the reinforcement learning agent. The training module 520 may use the reward obtained by the reinforcement learning agent during the training process as feedback to the text generation model and / or the text parsing model, and update the text generation model and / or the text parsing model based on the feedback.
[0115] The reinforcement learning-based text interaction method disclosed in the present invention can also be implemented as a text interaction device. Figure 6 The structure diagram of the text interaction device according to an embodiment of the present disclosure is shown. The functional units of the text interaction device can be implemented by hardware, software, or a combination of hardware and software that implements the principles of the present disclosure. It can be understood by those skilled in the art that Figure 6 The functional units described can be combined or divided into sub-units to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional units described herein. The following is a brief description of the functional units that the text interaction device can have and the operations that each functional unit can perform. For the details involved, please refer to the relevant description above, which will not be repeated here.
[0116] The text interaction device 600 is used in a text interaction scenario involving multiple participants, at least one of the multiple participants being a reinforcement learning agent device.
[0117] See also Figure 6 , the text interaction device 600 may include a selection module 610 and a processing module 620 .
[0118] The selection module 610 is used to select a text generation model that is consistent with the target speech style from multiple text generation models, wherein the text generation model is used to process the input text to obtain an output text that matches the style type corresponding to the text generation model, and the output text is more in line with the natural language expression habits than the input text. The text generation model can be obtained using the text generation method described above.
[0119] Processing module 620 is used to generate a sixth text corresponding to the fifth text using the selected text generation model if the action selected by the reinforcement learning agent from the action space based on the state in the state space during any round of interaction includes the fifth text, and use the sixth text as the text output by the reinforcement learning agent in the current round.
[0120] The text interaction device 600 may further include a determination module and a provision module. The determination module is used to determine the style type of the speech text output by the target participant, wherein the target participant is a real person user. The provision module is used to provide the determined style type to the target participant.
[0121] The text interaction device 600 may also include a parsing module and a training module. The parsing module is used to parse the speech text output by the target participant to obtain a logic text for representing the sentence trunk logic of the speech text. The training module is used to train a text generation model for simulating the speech style of the target participant based on the speech text output by the target participant and the logic text.
[0122] Figure 7 A schematic diagram of the structure of a computing device that can be used to implement the above-mentioned text generation method or text interaction method according to an embodiment of the present disclosure is shown.
[0123] See also Figure 7 , the computing device 700 includes a memory 710 and a processor 720 .
[0124] The processor 720 may be a multi-core processor or may include multiple processors. In some embodiments, the processor 720 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, the processor 720 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).
[0125] The memory 710 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 720 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 710 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 710 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (e.g., DVD-ROM, double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0126] The memory 710 stores executable codes, and when the executable codes are processed by the processor 720 , the processor 720 can execute the text generation method or text interaction method mentioned above.
[0127] The text generation and text interaction method, device and apparatus according to the present invention have been described above in detail with reference to the accompanying drawings.
[0128] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present invention.
[0129] Alternatively, the present invention may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present invention.
[0130] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.
[0131] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0132] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terms used herein are selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A text generation method, characterized in that: include: Constructing a training set based on a plurality of first texts corresponding to the same style type and a second text corresponding to the first text, wherein the second text is used to characterize the sentence trunk logic of the first text; The training set is used to train a text generation model, wherein the text generation model is used to process the input text to obtain an output text with a predetermined style and which is more in line with natural language expression habits than the input text.
2. The method according to claim 1, characterized in that: The first text is an unannotated text that conforms to natural language expression habits, and the method further includes: Predicting the style type of the first text using a style classification model; The first text is parsed using a text parsing model to obtain a second text corresponding to the first text.
3. The method according to claim 2, characterized in that Also includes: Generate a fourth text corresponding to the third text using a text generation model; The text parsing model is trained based on the third text and the fourth text.
4. The method according to claim 3, characterized in that The method involves multiple participants, at least one of the multiple participants is a reinforcement learning agent, and the method further includes: Using the text selected by the reinforcement learning agent from the action space based on the state in the state space as the third text, and using the fourth text as the text output by the reinforcement learning agent in the current round; The text output by other participants is used as the first text, and the second text is used as the state in the state space of the reinforcement learning agent.
5. The method according to claim 4, characterized in that Also includes: The rewards obtained by the reinforcement learning agent during the training process are used as feedback to the text generation model and / or the text parsing model, and the text generation model and / or the text parsing model are updated based on the feedback.
6. A text interaction method based on reinforcement learning, characterized in that: The method involves multiple participants, at least one of the multiple participants is a reinforcement learning agent, and the method includes: Selecting a text generation model consistent with the target speech style from a plurality of text generation models, wherein the text generation model is used to process the input text to obtain an output text matching the style type corresponding to the text generation model, and the output text is more in line with the natural language expression habits than the input text; If the action selected by the reinforcement learning agent from the action space based on the state in the state space during any round of interaction includes the fifth text, a sixth text corresponding to the fifth text is generated using the selected text generation model, and the sixth text is used as the text output by the reinforcement learning agent in the current round.
7. A text generation device, characterized in that: include: A construction module, configured to construct a training set based on a plurality of first texts corresponding to the same style type and a second text corresponding to the first text, wherein the second text is used to characterize the sentence trunk logic of the first text; A training module is used to train a text generation model using the training set, wherein the text generation model is used to process the input text to obtain an output text with a predetermined style and which is more in line with natural language expression habits than the input text.
8. A text interaction device based on reinforcement learning, characterized in that: The device is used in a text interaction scenario involving multiple participants, at least one of the multiple participants is a reinforcement learning agent, and the device includes: A selection module, for selecting a text generation model consistent with the target speech style from a plurality of text generation models, wherein the text generation model is used to process the input text to obtain an output text matching the style type corresponding to the text generation model, and the output text is more in line with the natural language expression habits than the input text; A processing module is used to generate a sixth text corresponding to the fifth text using a selected text generation model if the action selected by the reinforcement learning agent from the action space based on the state in the state space during any round of interaction includes a fifth text, and use the sixth text as the text output by the reinforcement learning agent in the current round.
9. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 6.
10. A non-transitory machine-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 6.
Citation Information
Cited By
Intelligent agent instance construction method and data processing method based on intelligent agent instance
CN118690779A
