A method and apparatus for processing dialogue text
By generating dual-stream inputs of time and speaker streams in dialogue text processing, the DSM model addresses the problem of insufficient speaker information, thereby improving the model's fidelity and task performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-28
- Publication Date
- 2026-04-03
AI Technical Summary
Existing technologies fail to effectively address speaker information when processing dialogue text, leading to problems such as misattribution, coreference errors, and missing information during model understanding and generation.
By splicing the speakers and utterances in the dialogue text in chronological order to form a time stream, and aggregating the utterances according to the order of the speakers to generate a speaker stream, this stream is used as input to a two-stream dialogue model and processed using the DSM model.
It improves the fidelity of the model in dialogue text processing, reduces the probability of comprehension errors caused by speaker switching, and enhances the performance and generalization ability of dialogue text processing tasks.
Smart Images

Figure CN115270817B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, specifically to a method and apparatus for processing dialogue text. Background Technology
[0002] Natural Language Processing (NLP) is a subfield of human language, computer science, and artificial intelligence, aiming to enable machines to understand, analyze, and utilize human language. NLP can be broadly divided into two areas: Natural Language Understanding and Natural Language Generation. Its processing objects include various types of text, such as documents, news, legal documents, web pages, and conversations. Conversations are a crucial means of information exchange for humans, including everyday chats, meetings, emails, and customer service interactions. The vast amounts of conversation data contain rich valuable information and knowledge; therefore, tasks related to conversational texts, such as conversation summarization, reading comprehension, and conversation generation, have been a focus of research in academia and industry in recent years.
[0003] In its early stages, NLP and dialogue tasks transitioned from rule-based methods to statistical methods. With the development of neural network-based dialogue models, such as encoder-decoder frameworks and Transformer pre-trained models, significant progress has been made in dialogue tasks. However, due to certain structural characteristics of dialogue text, dialogue tasks remain highly challenging. Compared to common documents, which are typically organized from a unified narrative perspective, dialogues often involve many different speakers, leading to diversity and frequent shifts in narrative perspective.
[0004] Existing technologies offer a dialogue text processing method based on a Transformer pre-trained model. This method adopts a common practice in the document domain, treating the entire dialogue as a single, chronologically ordered utterance stream as input to the model. However, the utterances of different speakers are interleaved within this single utterance stream, which may weaken the semantic continuity of each speaker. Furthermore, this method requires the model to handle frequent speaker switching, often resulting in fidelity issues during understanding and generation, such as misattribution, coreference errors, and missing information, hindering the practical application of neural network dialogue models. Summary of the Invention
[0005] This application provides a method and apparatus for processing dialogue text, in order to address the problem that existing technologies in the field of dialogue text processing in natural language processing lack special attention to speaker-centered information.
[0006] The first aspect of this application provides a method for processing dialogue text, including:
[0007] Obtain the dialogue text, which includes multiple groups of speakers and their corresponding utterances in a sequential dialogue.
[0008] By splicing the speakers and utterances in the dialogue text in chronological order, the time stream of the dialogue text is obtained.
[0009] According to the order in which the speakers first appear in the dialogue text, all the utterances of different speakers in the dialogue text are aggregated to obtain the speaker stream of the dialogue text;
[0010] Using the time stream and the speaker stream as input to a preset two-stream dialogue model, the corresponding output for the dialogue text task is obtained.
[0011] Optionally, the step of aggregating all utterances of different speakers in the dialogue text according to the order in which they first appear in the dialogue text to obtain the speaker stream of the dialogue text includes:
[0012] By aggregating all the utterances of different speakers in the dialogue text in chronological order, multiple utterance sets are obtained, wherein the utterance sets include the speaker and all the utterances corresponding to the speaker;
[0013] The multiple sets of utterances are spliced together according to the order in which the speakers first appear in the dialogue text to obtain the speaker stream of the dialogue text.
[0014] Optionally, the preset dual-stream dialogue model is a DSM model, which adopts an encoder and decoder structure;
[0015] The encoder includes an input embedding layer, a positional encoder, an encoder backbone, and encoder branches connected in sequence; the encoder backbone includes a multi-layer encoder backbone module, each of which includes a self-attention layer and a fully connected layer connected in sequence; the encoder branches include a time-flow branch and a speaker-flow branch, both of which include a multi-layer encoder branch module, each of which includes a self-attention layer and a fully connected layer connected in sequence.
[0016] The decoder includes an output embedding layer, a positional encoding layer, a decoder backbone, a linear output layer, and a Softmax layer connected in sequence. The decoder backbone includes a multi-layer decoding module, each of which includes a self-attention layer, a first cross-attention module, a second cross-attention module, and a fully connected layer connected in sequence. The speaker flow branch is connected to the first cross-attention module, and the time flow branch is connected to the second cross-attention module.
[0017] Optionally, the step of using the time stream and the speaker stream as input to a preset two-stream dialogue model to obtain a corresponding output for the dialogue text task includes:
[0018] The time stream and the speaker stream are passed through the encoder to obtain the context representation of the time stream and the context representation of the speaker stream, respectively.
[0019] The preceding output of the decoder is processed through the output embedding layer and position encoding of the decoder to obtain the first decoded embedding representation;
[0020] The first decoded embedding representation is passed through multiple decoding modules of the decoder backbone to obtain the second decoded embedding representation. In each decoding module, the first decoded embedding representation passes sequentially through a self-attention layer, a first cross-attention module that interacts with the speaker stream, a second cross-attention module that interacts with the time stream, and a fully connected layer. The first cross-attention module is used to input the context representation of the speaker stream, and the second cross-attention module is used to input the context representation of the time stream.
[0021] The second decoded embedding representation is passed through the linear output layer and the Softmax layer to obtain the probability distribution of the current output.
[0022] Optionally, the time stream and the speaker stream are processed by the encoder to obtain contextual representations of the time stream and the speaker stream, respectively, including:
[0023] The time stream and the speaker stream are passed through the input embedding layer and position encoding of the encoder to obtain the first encoded embedding representation of the time stream and the first encoded embedding representation of the speaker stream, respectively.
[0024] The first encoded embedding representation of the time stream and the first encoded embedding representation of the speaker stream are passed through the encoder backbone to obtain the intermediate representation of the time stream and the intermediate representation of the speaker stream, respectively.
[0025] The intermediate representation of the time stream is passed through the time stream branches to obtain the context representation of the time stream;
[0026] The intermediate representation of the speaker stream is passed through the speaker stream branch to obtain the context representation of the speaker stream.
[0027] Optionally, the preset dual-stream dialogue model includes a single-input encoder-decoder model, a dual-input encoder-decoder model, a single-input encoder model, a dual-input encoder model, a single-input decoder model, or a dual-input decoder model.
[0028] A second aspect of this application provides a dialog text processing apparatus, which is used to execute the dialog text processing method provided in the first aspect of this application, including:
[0029] The acquisition module is used to acquire dialogue text, which includes multiple groups of speakers and their corresponding utterances in a sequential dialogue.
[0030] The time stream module is used to splice the speakers and utterances in the dialogue text in chronological order to obtain the time stream of the dialogue text.
[0031] The speaker flow module is used to aggregate all the utterances of different speakers in the dialogue text according to the order in which the speakers first appear in the dialogue text, so as to obtain the speaker flow of the dialogue text.
[0032] The dual-stream input module is used to take the time stream and the speaker stream as input to a preset dual-stream dialogue model to obtain the corresponding output for the dialogue text task.
[0033] Optionally, the speaker flow module is further configured to:
[0034] By aggregating all the utterances of different speakers in the dialogue text in chronological order, multiple utterance sets are obtained, wherein the utterance sets include the speaker and all the utterances corresponding to the speaker;
[0035] The multiple sets of utterances are spliced together according to the order in which the speakers first appear in the dialogue text to obtain the speaker stream of the dialogue text.
[0036] Optionally, the dual-stream input module has a built-in preset dual-stream dialogue model, which is a DSM model, and the DSM model adopts an encoder and decoder structure.
[0037] The encoder includes an input embedding layer, a positional encoder, an encoder backbone, and encoder branches connected in sequence; the encoder backbone includes a multi-layer encoder backbone module, each of which includes a self-attention layer and a fully connected layer connected in sequence; the encoder branches include a time-flow branch and a speaker-flow branch, both of which include a multi-layer encoder branch module, each of which includes a self-attention layer and a fully connected layer connected in sequence.
[0038] The decoder includes an output embedding layer, a positional encoding layer, a decoder backbone, a linear output layer, and a Softmax layer connected in sequence. The decoder backbone includes a multi-layer decoding module, each of which includes a self-attention layer, a first cross-attention module, a second cross-attention module, and a fully connected layer connected in sequence. The speaker flow branch is connected to the first cross-attention module, and the time flow branch is connected to the second cross-attention module.
[0039] Optionally, the dual-stream input module is further configured as follows:
[0040] The time stream and the speaker stream are processed by the encoder to obtain the context representation of the time stream and the context representation of the speaker stream, respectively.
[0041] The preceding output of the decoder is processed by the output embedding layer and position encoding of the decoder to obtain the first decoded embedding representation;
[0042] The first decoding embedding representation is passed through multiple decoding modules of the decoder backbone to obtain the second decoding embedding representation. In each decoding module, the first decoding embedding representation passes sequentially through a self-attention layer, a first cross-attention module that interacts with the speaker stream, a second cross-attention module that interacts with the time stream, and a fully connected layer. The first cross-attention module is used to input the context representation of the speaker stream, and the second cross-attention module is used to input the context representation of the time stream.
[0043] The second decoding embedding represents the probability distribution of the current output obtained after passing through the linear output layer and the Softmax layer.
[0044] As can be seen from the above technical solutions, this application provides a dialogue text processing method and apparatus. By concatenating speakers and utterances in the dialogue text in chronological order to obtain a time stream, and aggregating all utterances from different speakers in the dialogue text to obtain a speaker stream, the obtained time stream and speaker stream are used as dual-stream inputs to fully utilize dialogue information. The time stream and speaker stream represent two directions for human understanding of dialogue. The time stream helps in understanding the development of the dialogue, while the speaker stream aggregates utterances by speaker, which is beneficial for understanding information from different speakers. Furthermore, by reducing speaker switching, the probability of model misunderstanding errors can be reduced, thereby improving the model's fidelity. In addition, the speaker stream of this application is automatically generated without requiring any other resource consumption, such as additional model prediction and manual annotation, which allows this application to be applied cost-effectively and conveniently.
[0045] This application views dialogue text from a two-dimensional "time-speaker" perspective, thereby obtaining two input representations of the dialogue: time flow and speaker flow. The former helps the model understand the development logic of the dialogue from a temporal perspective, while the latter helps to aggregate the discourse information of each speaker from the speaker's perspective. Compared with traditional methods, the main advantage of this application is that it can improve the performance of dialogue text processing tasks, while also having better generalization ability. Attached Figure Description
[0046] Figure 1 A flowchart illustrating a dialogue text processing method provided in an embodiment of this application;
[0047] Figure 2 A flowchart for determining speaker flow is provided as an embodiment of this application;
[0048] Figure 3 This is a schematic diagram of the structure of the DSM model provided in the embodiments of this application;
[0049] Figure 4 This is a schematic diagram of the structure of a two-stream dialogue model provided in an embodiment of this application;
[0050] Figure 5 This is a schematic diagram of another two-stream dialogue model provided in an embodiment of this application;
[0051] Figure 6 This is a schematic diagram of another two-stream dialogue model provided in an embodiment of this application;
[0052] Figure 7 This is a schematic diagram of another two-stream dialogue model provided in an embodiment of this application. Detailed Implementation
[0053] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0054] The terminology used in the following embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, “at least one,” “one or more” refers to one, two, or more than two, and “multiple” refers to two or more. The term “and / or” is used to describe the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can indicate: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character “ / ” generally indicates that the preceding and following related objects are in an “or” relationship.
[0055] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0056] See Figure 1 This application provides a dialog text processing method, including steps S1 to S4.
[0057] S1. Obtain the dialogue text.
[0058] The dialogue text in this application embodiment includes multiple groups of speakers and their corresponding utterances in a sequential dialogue, for example, in Figure 1The dialogue text includes nine sets of speaker-speaker dialogues, i.e., nine dialogue segments. The first set is: "#Person1#: Welcome to Garden Restaurant. Would you like to order?"; the second set is: "#Person2#: Yes, please."; the third set is: "#Person1#: What would you like to drink?"; the fourth set is: "#Person3#: A bottle of water."; the fifth set is: "#Person4#: A bottle of juice."; the sixth set is: "#Person2#: Coke."; the seventh set is: "#Person1#: What would you like to eat?"; the eighth set is: "#Person3#: We'll have a fish pizza."; and the ninth set is: "#Person2#: And vegetablesoup."
[0059] It should be noted that the dialogue text in this application embodiment can be obtained by directly exporting the text generated during the communication process, or by performing speech recognition on the voice data generated during the communication process, or by recognizing an image containing dialogue text. This application embodiment does not specifically limit this.
[0060] It should be noted that, in this embodiment of the application, the obtained dialogue text is the corresponding text for which a dialogue text task needs to be completed. For example, if the dialogue text task is a dialogue summary, the determined dialogue text is the dialogue text for which the summary needs to be extracted.
[0061] The dialogue text in this embodiment can be represented as:
[0062] π = {(s1, c1), ..., (s n c n )};
[0063] Where π represents the dialogue text including n dialogue segments, (s i c i ) is a set of utterances between speakers and their corresponding statements. i As the speaker, c i For specific utterances, i = 1, 2, ..., n.
[0064] S2. The speakers and utterances in the dialogue text are spliced together in chronological order to obtain the time stream of the dialogue text.
[0065] By piecing together the speakers and their utterances in chronological order, a timeline is obtained, which can be represented as:
[0066]
[0067] Where u represents the time stream, and ⊕ represents the string concatenation function.
[0068] S3. According to the order in which the speakers first appear in the dialogue text, aggregate all the utterances of different speakers in the dialogue text to obtain the speaker stream of the dialogue text.
[0069] In a dialogue text that includes multiple groups of speakers and their corresponding utterances, all utterances of different speakers in the dialogue text are aggregated in chronological order to obtain multiple utterance sets. The multiple utterance sets are then concatenated according to the order in which the speakers first appear in the dialogue text to obtain the speaker stream of the dialogue text.
[0070] For example, in Figure 1The shades of color represent different speakers. For speaker Person1, aggregating all of Person1's utterances in chronological order yields the set of utterances for Person1 as "#Person1#: Welcome to Garden Restaurant. Would you like to order? What would you like to drink? What would you like to eat?". For speaker Person2, aggregating all of Person2's utterances in chronological order yields the set of utterances for Person2 as "#Person2#: Yes, please. Coke. And vegetable soup.". For speaker Person3, aggregating all of Person3's utterances in chronological order yields the set of utterances for Person3 as "#Person3#: A bottle of water. We'll have a fish pizza.". For speaker Person4, aggregating all of Person4's utterances in chronological order yields the set of utterances for Person4 as "#Person4#: A bottle of juice.". After obtaining multiple sets of utterances, the order in which the speakers first appear in the dialogue text is determined, namely, the order in which Person1, Person2, Person3, and Person4 first appear in the dialogue text. In this embodiment, the order is Person1, Person2, Person3, and Person4. The corresponding utterance sets are then assembled according to this order to obtain the speaker stream.
[0071] This application also provides a method for determining the speaker flow of dialogue text, see [link to relevant documentation]. Figure 2 The speaker stream is represented as v, and the method includes:
[0072] Based on the dialogue text, a speaker set and a corresponding set of multiple discourses are established. The initial values of the speaker set and the multiple discourse sets both include various different speakers, wherein the various different speakers are arranged in the order of their first appearance in the dialogue text.
[0073] For example, the speaker set is represented as {Person1, Person2, Person3, Person4}, and the initial values of the multiple discourse sets are represented as {Person1, Person2, Person3, Person4}, with a one-to-one correspondence between the speaker set and the initial values of the multiple discourse sets.
[0074] Iterate through multiple groups of speakers and their corresponding utterances in the dialogue text. Based on the speakers in each group, determine the position of the same speaker in the speaker set, that is, determine the corresponding position in multiple utterance sets. Then, append the utterances of each group to the speaker at the corresponding position in the multiple utterance sets to update the utterance sets.
[0075] For example, for a certain group of speakers and their corresponding utterances during the traversal, such as the fourth group of speakers and their corresponding utterances, i.e., "#Person3#: A bottle of water.", based on the speaker Person3 in the fourth group, the position of the speaker who is the same as Person3 in the speaker set {Person1, Person2, Person3, Person4} is determined as the third element. Then, the utterance set T3 represented by the third element is selected from the corresponding multiple utterance sets, and the utterance "A bottle of water." in the fourth group is concatenated into T3 to update T3.
[0076] S4. Using the time stream and the speaker stream as input to a preset two-stream dialogue model, obtain the corresponding output for the dialogue text task.
[0077] This application embodiment views the dialogue text from a two-dimensional "time-speaker" perspective, thereby obtaining two input representations of the dialogue: a time stream and a speaker stream. The former helps the model understand the development logic of the dialogue from a temporal perspective, while the latter helps aggregate the utterance information of each speaker from the speaker's perspective. After obtaining the time stream and speaker stream, they are used as dual-stream inputs to a preset dual-stream dialogue model to obtain the contextual representation of the dual streams and generate corresponding content. The dual-stream input of this application embodiment consists of the time stream and speaker stream of the dialogue text. The basic structure of both is "speaker + utterance," where the time stream is obtained by splicing the dialogue text in chronological order, and the speaker stream is formed by aggregating the dialogue text according to the order of different speakers.
[0078] The dual-stream dialogue model preset in this application embodiment can be the DSM (Dual-Stream Model for dialogue text) model based on the encoder-decoder framework provided in this application embodiment. The DSM model is built on the encoder-decoder framework and undergoes targeted structural modifications according to the characteristics of dual-stream input. The DSM encoder consists of a backbone-branch network, where the backbone and branches are used to capture the commonalities and unique characteristics of the two speech streams, respectively. Each encoder layer includes a self-attention layer and a fully connected layer. The output of the DSM encoder yields the temporal and speaker stream context representations of the dialogue text. The DSM decoder layer inherits from the Transformer decoder layer; however, unlike the Transformer, this application embodiment utilizes two cross-attention modules to capture information from the temporal and speaker streams.
[0079] See Figure 3 This is a schematic diagram of the structure of a DSM model provided in an embodiment of this application. The DSM model adopts an encoder and decoder structure.
[0080] The encoder includes an input embedding layer, a positional encoder, an encoder backbone, and encoder branches connected in sequence. The encoder backbone includes multi-layer encoder backbone modules. For example, the depth of the encoder backbone can be N1, and each encoder backbone module includes a self-attention layer and a fully connected layer connected in sequence. The encoder branches include a temporal flow branch and a speaker flow branch. Both the temporal flow branch and the speaker flow branch include multi-layer encoder branch modules. For example, the depth of the two branches can be N2, and each encoder branch module includes a self-attention layer and a fully connected layer connected in sequence.
[0081] The decoder includes an output embedding layer, a positional encoding layer, a decoder backbone, a linear output layer, and a softmax layer connected in sequence. The decoder backbone includes a multi-layer decoding module, each of which includes a self-attention layer, a first cross-attention module, a second cross-attention module, and a fully connected layer connected in sequence. The speaker flow branch is connected to the first cross-attention module, and the time flow branch is connected to the second cross-attention module.
[0082] After the temporal and speaker streams of the dialogue text are input into the DSM model, they will sequentially pass through various parts of the DSM model. The encoder part includes:
[0083] S401. The time stream and the speaker stream are processed through the input embedding layer and position encoding of the encoder to obtain the first encoded embedding representation of the time stream and the first encoded embedding representation of the speaker stream, respectively. The encoding process can be represented as follows:
[0084] e t ,e s =Embedding(x t ,x s )+PosEmb(x t ,x s )
[0085] Among them, e t For the first encoded embedding representation of the time stream, e s For the first encoded embedding representation of the speaker stream, x t For time flow, x s For the speaker's flow.
[0086] S402. The first encoded embedding representation of the time stream and the first encoded embedding representation of the speaker stream are passed through an encoder backbone composed of N1 layers of encoding backbone modules to obtain the intermediate representation of the time stream and the intermediate representation of the speaker stream, respectively. The encoding process can be represented as follows:
[0087] E' t ,E' s =Trunk(e t ,e s )
[0088] Among them, E′ t E′ is an intermediate representation of the time stream. s This is an intermediate representation of the speaker stream.
[0089] S403. The intermediate representation of the time stream is passed through the time stream branch to obtain the context representation of the time stream; the intermediate representation of the speaker stream is passed through the speaker stream branch to obtain the context representation of the speaker stream. The depth of the time stream branch and the speaker stream branch can be N2, which is used to further encode the embedding representation of the two streams.
[0090] The encoding process for this step can be represented as:
[0091]
[0092]
[0093] in, For the contextual representation of the time flow, A contextual representation of the speaker stream.
[0094] After obtaining the context representation of the two streams, it is input into the decoder for decoding and generation. The decoder part includes:
[0095] S404. The preceding output of the decoder is processed through the output embedding layer and position encoding of the decoder to obtain the first decoded embedding representation.
[0096] S405. The first decoded embedding representation is passed through a multi-layer decoding module of the decoder backbone. The depth of the decoder backbone can be N3 to obtain a second decoded embedding representation. In each decoding module, the first decoded embedding representation passes sequentially through a self-attention layer, a first cross-attention module that interacts with the speaker stream, a second cross-attention module that interacts with the time stream, and a fully connected layer. The first cross-attention module is used to input the context representation of the speaker stream, and the second cross-attention module is used to input the context representation of the time stream.
[0097] S406. The second decoded embedding representation is passed through the linear output layer and the Softmax layer to obtain the probability distribution of the current output.
[0098] It should be noted that the number of layers N1, N2, and N3 can be adjusted according to the actual situation, and this application embodiment does not impose specific limitations.
[0099] Furthermore, the dual-stream input generated in the embodiments of this application can also be applied to other model structures, such as the Transformer model. Further, see [link to related documentation]. Figure 4 A single-input encoder-decoder model. Figure 5 A dual-input encoder-decoder model. Figure 6 The models in China are single-input encoders or dual-input encoders, which are mainly based on encoder structures. Figure 7 The single-input decoder model or dual-input decoder model, which are based on the decoder structure, can be used as a preset dual-stream dialogue model to process dual-stream inputs to complete different tasks.
[0100] According to the embodiments of this application, the time stream and speaker stream of the dialogue text are obtained, and then fed into a preset two-stream dialogue model to obtain the final output of the dialogue text task. The following embodiments will further illustrate this application.
[0101] In some embodiments, the dialogue text task is dialogue summarization. The dialogue summarization task aims to take a dialogue text as input and generate a summary of that text using a model. In embodiments of the dialogue summarization task, the original dialogue text is processed using the dual-stream input generation method proposed in the preceding embodiments of this application to obtain a time stream and a speaker stream. The time stream and speaker stream are then fed into a model such as the DSM model proposed in the preceding embodiments of this application. The DSM encoder encodes the time stream and speaker stream respectively to obtain their respective context representations. The DSM decoder then uses the time stream and speaker stream context representations to generate words in the summary one by one. Each time, the decoder outputs a probability distribution on the vocabulary, indicating which words might be generated. The decoder then selects the word with the highest probability as the word at the current time step and proceeds to generate the next word until the model predicts that the currently generated word is a <sentence end marker>.
[0102] In another embodiment, the dialogue text task is dialogue reading comprehension. The dialogue reading comprehension task aims to take a dialogue text and a specific question as input, and generate the answer to the question using a model. In this embodiment, the original dialogue text is processed using the dual-stream input generation method proposed in the preceding embodiments of this application to obtain a time stream and a speaker stream. The specific question is then concatenated with the time stream or speaker stream. For example, the question is inserted at the beginning of the time stream or speaker stream, and a special marker separates the question from the time stream or speaker stream. Then, the input is fed into, for example, the DSM model proposed in the preceding embodiments of this application. The DSM encoder encodes their respective context representations, and the DSM decoder uses these two context representations to generate words in the answer one by one. Each time, the decoder outputs a probability distribution on the vocabulary, i.e., which words the current generated word might be. The decoder then selects the word with the highest probability as the word at the current time step and generates the next word, until the model predicts that the currently generated word is a <sentence end marker>.
[0103] In another embodiment, the dialogue text task is dialogue generation. The dialogue generation task aims to take a dialogue text as input and use a model to generate a sentence as an appropriate response. In this embodiment, the original dialogue text is processed using the dual-stream input generation method proposed in the preceding embodiments of this application to obtain a time stream and a speaker stream. The time stream and speaker stream are then fed into a model such as the DSM model proposed in this scheme. The DSM encoder encodes the time stream and speaker stream respectively to obtain their respective context representations. The DSM decoder then uses the time stream and speaker stream context representations to generate words in the dialogue response one by one. Each time, the decoder outputs a probability distribution on a vocabulary, indicating which words might be generated. The decoder then selects the word with the highest probability as the word at the current time step and proceeds to generate the next word until the model predicts that the currently generated word is a <sentence end marker>.
[0104] A second aspect of this application also provides a dialog text processing apparatus, which is used to execute the dialog text processing method provided above, including:
[0105] The acquisition module is used to acquire dialogue text, which includes multiple groups of speakers and their corresponding utterances in a sequential dialogue.
[0106] The time-stream module is used to concatenate the speakers and utterances in the dialogue text in chronological order to obtain the time-stream of the dialogue text.
[0107] The speaker flow module is used to aggregate all the utterances of different speakers in the dialogue text according to the order in which the speakers first appear in the dialogue text, so as to obtain the speaker flow of the dialogue text.
[0108] The dual-stream input module is used to take the time stream and the speaker stream as input to a preset dual-stream dialogue model to obtain the corresponding output for the dialogue text task.
[0109] Optionally, the speaker flow module is further configured to:
[0110] By aggregating all the utterances of different speakers in the dialogue text in chronological order, multiple utterance sets are obtained, wherein each utterance set includes the speaker and all the utterances corresponding to the speaker.
[0111] The multiple sets of utterances are spliced together according to the order in which the speakers first appear in the dialogue text to obtain the speaker stream of the dialogue text.
[0112] Optionally, the dual-stream input module has a built-in preset dual-stream dialogue model, which is a DSM model, and the DSM model adopts an encoder and decoder structure.
[0113] The encoder includes an input embedding layer, a position encoder, an encoder backbone, and encoder branches connected in sequence; the encoder backbone includes a multi-layer encoder backbone module, and each encoder backbone module includes a self-attention layer and a fully connected layer connected in sequence.
[0114] The encoder branches include a time-stream branch and a speaker-stream branch. Both the time-stream branch and the speaker-stream branch include multi-layer coding branch modules. Each coding branch module includes a self-attention layer and a fully connected layer connected in sequence.
[0115] The decoder includes an output embedding layer, a positional encoding layer, a decoder backbone, a linear output layer, and a Softmax layer connected in sequence. The decoder backbone includes a multi-layer decoding module, each of which includes a self-attention layer, a first cross-attention module, a second cross-attention module, and a fully connected layer connected in sequence. The speaker flow branch is connected to the first cross-attention module, and the time flow branch is connected to the second cross-attention module.
[0116] Optionally, the dual-stream input module is further configured as follows:
[0117] The time stream and the speaker stream are processed by the encoder to obtain the context representation of the time stream and the context representation of the speaker stream, respectively.
[0118] The preceding output of the decoder is processed by the output embedding layer and position encoding to obtain the first decoded embedding representation.
[0119] The first decoding embedding representation is passed through multiple decoding modules of the decoder backbone to obtain the second decoding embedding representation. In each decoding module, the first decoding embedding representation passes sequentially through a self-attention layer, a first cross-attention module that interacts with the speaker stream, a second cross-attention module that interacts with the time stream, and a fully connected layer. The first cross-attention module is used to input the context representation of the speaker stream, and the second cross-attention module is used to input the context representation of the time stream.
[0120] The second decoding embedding represents the probability distribution of the current output obtained after passing through the linear output layer and the Softmax layer.
[0121] As can be seen from the above technical solutions, this application provides a dialogue text processing method and apparatus. By concatenating speakers and utterances in the dialogue text in chronological order to obtain a time stream, and aggregating all utterances from different speakers in the dialogue text to obtain a speaker stream, the obtained time stream and speaker stream are used as dual-stream inputs to fully utilize dialogue information. The time stream and speaker stream represent two directions for human understanding of dialogue. The time stream helps in understanding the development of the dialogue, while the speaker stream aggregates utterances by speaker, which is beneficial for understanding information from different speakers. Furthermore, by reducing speaker switching, the probability of model misunderstanding is reduced, thereby improving model fidelity. In addition, the speaker stream in this application is automatically generated without requiring any other resource consumption, such as additional model prediction and manual annotation, which allows this application to be applied cost-effectively and conveniently.
[0122] This application's embodiments view dialogue text from a two-dimensional "time-speaker" perspective, thereby obtaining two input representations of the dialogue: a time flow and a speaker flow. The former helps the model understand the development logic of the dialogue from a temporal perspective, while the latter helps aggregate each speaker's discourse information from the speaker's perspective. Compared to traditional methods, the main advantage of this application's embodiments is that it can improve the performance of dialogue text processing tasks, while also having better generalization ability.
[0123] The embodiments described above do not constitute a limitation on the scope of protection of this application.
Claims
1. A method for processing dialogue text, characterized in that, include: Obtain the dialogue text, which includes multiple groups of speakers and their corresponding utterances in a sequential dialogue. By splicing the speakers and utterances in the dialogue text in chronological order, the time stream of the dialogue text is obtained. According to the order in which the speakers first appear in the dialogue text, all the utterances of different speakers in the dialogue text are aggregated to obtain the speaker stream of the dialogue text; Using the time stream and the speaker stream as input to a preset two-stream dialogue model, the corresponding output for the dialogue text task is obtained. The process of aggregating all utterances of different speakers in the dialogue text according to the order in which they first appear in the text, to obtain the speaker stream of the dialogue text, includes: By aggregating all the utterances of different speakers in the dialogue text in chronological order, multiple utterance sets are obtained, wherein the utterance sets include the speaker and all the utterances corresponding to the speaker; The multiple sets of utterances are spliced together according to the order in which the speakers first appear in the dialogue text to obtain the speaker stream of the dialogue text.
2. The dialogue text processing method according to claim 1, characterized in that, The preset dual-stream dialogue model is a DSM model, which adopts an encoder and decoder structure. The encoder includes an input embedding layer, a positional encoder, an encoder backbone, and encoder branches connected in sequence; the encoder backbone includes a multi-layer encoder backbone module, each of which includes a self-attention layer and a fully connected layer connected in sequence; the encoder branches include a time-flow branch and a speaker-flow branch, both of which include a multi-layer encoder branch module, each of which includes a self-attention layer and a fully connected layer connected in sequence. The decoder includes an output embedding layer, a positional encoding layer, a decoder backbone, a linear output layer, and a Softmax layer connected in sequence. The decoder backbone includes a multi-layer decoding module, each of which includes a self-attention layer, a first cross-attention module, a second cross-attention module, and a fully connected layer connected in sequence. The speaker flow branch is connected to the first cross-attention module, and the time flow branch is connected to the second cross-attention module.
3. The dialogue text processing method according to claim 2, characterized in that, The step of using the time stream and the speaker stream as input to a preset two-stream dialogue model to obtain a corresponding output for the dialogue text task includes: The time stream and the speaker stream are passed through the encoder to obtain the context representation of the time stream and the context representation of the speaker stream, respectively. The preceding output of the decoder is processed through the output embedding layer and position encoding of the decoder to obtain the first decoded embedding representation; The first decoded embedding representation is passed through multiple decoding modules of the decoder backbone to obtain the second decoded embedding representation. In each decoding module, the first decoded embedding representation passes sequentially through a self-attention layer, a first cross-attention module that interacts with the speaker stream, a second cross-attention module that interacts with the time stream, and a fully connected layer. The first cross-attention module is used to input the context representation of the speaker stream, and the second cross-attention module is used to input the context representation of the time stream. The second decoded embedding representation is passed through the linear output layer and the Softmax layer to obtain the probability distribution of the current output.
4. The dialogue text processing method according to claim 3, characterized in that, The time stream and the speaker stream are processed by the encoder to obtain contextual representations of the time stream and the speaker stream, respectively, including: The time stream and the speaker stream are passed through the input embedding layer and position encoding of the encoder to obtain the first encoded embedding representation of the time stream and the first encoded embedding representation of the speaker stream, respectively. The first encoded embedding representation of the time stream and the first encoded embedding representation of the speaker stream are passed through the encoder backbone to obtain the intermediate representation of the time stream and the intermediate representation of the speaker stream, respectively. The intermediate representation of the time stream is passed through the time stream branches to obtain the context representation of the time stream; The intermediate representation of the speaker stream is passed through the speaker stream branch to obtain the context representation of the speaker stream.
5. The dialogue text processing method according to claim 1, characterized in that, The preset dual-stream dialogue model includes a single-input encoder-decoder model, a dual-input encoder-decoder model, a single-input encoder model, a dual-input encoder model, a single-input decoder model, or a dual-input decoder model.
6. A dialog text processing device, characterized in that, The dialogue text device is used to perform the dialogue text processing method according to any one of claims 1 to 5, including: The acquisition module is used to acquire dialogue text, which includes multiple groups of speakers and their corresponding utterances in a sequential dialogue. The time stream module is used to splice the speakers and utterances in the dialogue text in chronological order to obtain the time stream of the dialogue text. The speaker flow module is used to aggregate all the utterances of different speakers in the dialogue text according to the order in which the speakers first appear in the dialogue text, so as to obtain the speaker flow of the dialogue text. A dual-stream input module is used to take the time stream and the speaker stream as input to a preset dual-stream dialogue model to obtain the corresponding output for the dialogue text task. The speaker flow module is further configured as follows: By aggregating all the utterances of different speakers in the dialogue text in chronological order, multiple utterance sets are obtained, wherein the utterance sets include the speaker and all the utterances corresponding to the speaker; The multiple sets of utterances are spliced together according to the order in which the speakers first appear in the dialogue text to obtain the speaker stream of the dialogue text.
7. A dialog text processing device according to claim 6, characterized in that, The dual-stream input module has a built-in preset dual-stream dialogue model, which is a DSM model, and the DSM model adopts an encoder and decoder structure. The encoder includes an input embedding layer, a positional encoder, an encoder backbone, and encoder branches connected in sequence; the encoder backbone includes a multi-layer encoder backbone module, each of which includes a self-attention layer and a fully connected layer connected in sequence; the encoder branches include a time-flow branch and a speaker-flow branch, both of which include a multi-layer encoder branch module, each of which includes a self-attention layer and a fully connected layer connected in sequence. The decoder includes an output embedding layer, a positional encoding layer, a decoder backbone, a linear output layer, and a Softmax layer connected in sequence. The decoder backbone includes a multi-layer decoding module, each of which includes a self-attention layer, a first cross-attention module, a second cross-attention module, and a fully connected layer connected in sequence. The speaker flow branch is connected to the first cross-attention module, and the time flow branch is connected to the second cross-attention module.
8. A dialog text processing device according to claim 7, characterized in that, The dual-stream input module is further configured as follows: The time stream and the speaker stream are processed by the encoder to obtain the context representation of the time stream and the context representation of the speaker stream, respectively. The preceding output of the decoder is processed by the output embedding layer and position encoding to obtain the first decoded embedding representation; The first decoding embedding representation is passed through multiple decoding modules of the decoder backbone to obtain the second decoding embedding representation. In each decoding module, the first decoding embedding representation passes sequentially through a self-attention layer, a first cross-attention module that interacts with the speaker stream, a second cross-attention module that interacts with the time stream, and a fully connected layer. The first cross-attention module is used to input the context representation of the speaker stream, and the second cross-attention module is used to input the context representation of the time stream. The second decoding embedding represents the probability distribution of the current output obtained after passing through the linear output layer and the Softmax layer.
Citation Information
Patent Citations
Multi-round dialogue text generation method capable of sensing dialogue context relative position information
CN113342947A
Depression interview dialogue generation method based on pre-training language model
CN113780012A