WO2023108981A1 - 文本生成模型的训练方法、装置、存储介质及计算机设备 - Google Patents

文本生成模型的训练方法、装置、存储介质及计算机设备 Download PDF

Info

Publication number
WO2023108981A1
WO2023108981A1 PCT/CN2022/089734 CN2022089734W WO2023108981A1 WO 2023108981 A1 WO2023108981 A1 WO 2023108981A1 CN 2022089734 W CN2022089734 W CN 2022089734W WO 2023108981 A1 WO2023108981 A1 WO 2023108981A1
Authority
WO
WIPO (PCT)
Prior art keywords
text
vector
matrix
reply
topic
Prior art date
Application number
PCT/CN2022/089734
Other languages
English (en)
French (fr)
Inventor
舒畅
陈又新
肖京
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2023108981A1 publication Critical patent/WO2023108981A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/31Indexing; Data structures therefor; Storage structures
    • G06F16/316Indexing structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/3331Query processing
    • G06F16/334Query execution
    • G06F16/3344Query execution using natural language analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/214Generating training patterns; Bootstrap methods, e.g. bagging or boosting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/258Heading extraction; Automatic titling; Numbering
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/044Recurrent networks, e.g. Hopfield networks

Definitions

  • the present application relates to the technical field of machine learning, in particular to a training method, device, storage medium and computer equipment for a text generation model.
  • multi-round dialogue is always a research hotspot, and how to accurately and effectively generate reply text is of great significance to the research of multi-round dialogue.
  • the present application provides a text generation model training method, device, storage medium and computer equipment, mainly to ensure that the generated reply text is deeply related to the topic of the contextual dialogue, so that the generated reply text can fit multiple rounds of dialogue
  • the overall logic improves the accuracy of reply text generation.
  • a training method of a text generation model including:
  • the initial text vector generation model and the initial topic vector extraction model are iteratively trained to construct a text generation model.
  • a training device for a text generation model including:
  • An acquisition unit is used to acquire question text and multiple context texts in multiple rounds of dialogue
  • a generation unit configured to generate a first text vector matrix corresponding to the plurality of context texts and a reply text vector matrix corresponding to the question text by using an initial text vector generation model
  • An extraction unit configured to use an initial topic vector extraction model to respectively extract a contextual text topic vector corresponding to the first text vector matrix and a reply text topic vector corresponding to the reply text vector matrix;
  • a construction unit configured to construct a loss function based on the context text topic vector and the reply text topic vector
  • a training unit configured to iteratively train the initial text vector generation model and the initial topic vector extraction model based on the loss function to construct a text generation model.
  • a computer-readable storage medium on which computer-readable instructions are stored, and when the program is executed by a processor, the following steps are implemented:
  • the initial text vector generation model and the initial topic vector extraction model are iteratively trained to construct a text generation model.
  • a computer device including a memory, a processor, and computer-readable instructions stored on the memory and operable on the processor, and the processor implements the following steps when executing the program :
  • the initial text vector generation model and the initial topic vector extraction model are iteratively trained to construct a text generation model.
  • the application obtains the question text and A plurality of context texts; and using the initial text vector generation model to generate the first text vector matrix corresponding to the plurality of context texts and the reply text vector matrix corresponding to the question text; meanwhile, using the initial topic vector extraction model respectively Extracting the context text topic vector corresponding to the first text vector matrix and the reply text topic vector corresponding to the reply text vector matrix; and constructing a loss function based on the context text topic vector and the reply text topic vector; finally based on The loss function jointly iteratively trains the initial text vector generation model and the initial topic vector extraction model to construct a text generation model, thereby extracting the context topic vector and the reply text topic vector, and based on the context topic vector and reply text topic vector, build a loss function to train the text generation model, which can make the reply text topic vector and the context topic vector as close as possible, so as to
  • Fig. 1 shows a flow chart of a training method for a text generation model provided by an embodiment of the present application
  • Fig. 2 shows the flow chart of another kind of text generation model training method provided by the embodiment of the present application
  • FIG. 3 shows a schematic structural diagram of a training device for a text generation model provided by an embodiment of the present application
  • FIG. 4 shows a schematic structural diagram of a training device for another text generation model provided by an embodiment of the present application
  • FIG. 5 shows a schematic diagram of a physical structure of a computer device provided by an embodiment of the present application.
  • an embodiment of the present application provides a training method for a text generation model, as shown in FIG. 1 , the method includes:
  • the embodiment of the present application in the process of training the text generation model, it is possible to extract The context topic vector and the reply text topic vector, and use the context topic vector and reply text topic vector to construct a loss function, and train the text generation model based on the loss function, so as to ensure that the reply text generated by the text generation model can be compared with Contextual dialogue topics are deeply related and fit the overall logic of multiple rounds of dialogue.
  • the embodiment of the present application is mainly applied to the scenario of training a reply text generation model in multiple rounds of dialogue.
  • the execution subject of the embodiment of the present application is a device or device capable of training a reply text generation model, which may be specifically set on the server side.
  • the reply text generation model of multiple rounds of dialogue in order to train the reply text generation model of multiple rounds of dialogue, it is necessary to collect sample sentences in multiple rounds of dialogue in advance, including at least three sample sentences in one multi-round dialogue, and use the last sample sentence as the question text, At the same time, other sample sentences are used as context text.
  • the real reply text corresponding to the collected question text is known.
  • sample sentence 1 is "Let's go out to eat!
  • sample sentence 2 is "the weather is bad today, where do you want to eat?”
  • sample sentence 3 is "I I know a store that has just opened, and I can take the subway to eat.”
  • sample sentence 4 is “It’s good, you can’t get caught in the rain.”
  • the above sample sentence 1, sample sentence 2 and sample sentence 3 as the context text
  • sample sentence 4 (the last sample sentence) as the question text at the same time
  • based on the context text predict the predicted reply text corresponding to the question text, and extract the reply text topic vector and the context text topic vector at the same time
  • a loss function is constructed, and a text generation model is trained based on the loss function.
  • the initial text vector generation model includes an initial encoder, an initial decoder and a first initial feedforward neural network.
  • step 102 specifically includes: The embedding vector matrices corresponding to the texts are input into the initial encoder for encoding to obtain the first text vector matrices respectively corresponding to the multiple context texts; splicing a plurality of the first text vector matrices to obtain the A contextual text vector matrix corresponding to multiple rounds of dialogue; inputting the contextual text vector matrix and the embedding vector corresponding to the question text into the initial decoder for decoding to obtain a second text vector matrix corresponding to the question text ; Input the second text vector matrix into the first initial feed-forward neural network to obtain a reply text vector matrix corresponding to the question text.
  • inputting the embedding vector matrices respectively corresponding to the plurality of contextual texts into the initial encoder for encoding to obtain the first text vector matrices respectively corresponding to the plurality of contextual texts includes: The embedding vectors corresponding to the plurality of contextual texts are correspondingly linearly transformed to obtain the first query matrix, the first key matrix and the first value matrix respectively corresponding to the plurality of contextual texts; transposing the first key matrix Processing, multiplying the transposed first key matrix by the first query matrix to obtain attention intensity matrices respectively corresponding to the plurality of context texts; inputting the attention intensity matrix to the initial encoder
  • the softmax layer in the process is normalized to obtain the respective attention coefficient matrices corresponding to the plurality of context texts; the attention coefficient matrix is multiplied by the first value matrix to obtain the respective attention coefficient matrices of the plurality of context texts The corresponding matrix of first text vectors.
  • the initial decoder includes a first attention layer and a second attention layer
  • the context text vector matrix and the embedding vector corresponding to the question text are input into the initial decoder for decoding
  • Obtaining the second text vector matrix corresponding to the question text includes: inputting the embedding vector corresponding to the question text to the first attention layer for text feature extraction, and obtaining the third text vector matrix corresponding to the question text ;
  • a second text vector matrix corresponding to the question text is calculated according to the second query matrix, the second key matrix, and the second value matrix.
  • the text generation model of the embodiment of the present application mainly includes a text vector generation model and a topic vector extraction model.
  • the text vector generation model is mainly composed of a feedforward neural network, an encoder and a decoder in a transformer model, and the text vector generation model It includes 6 end-to-end encoders and 6 end-to-end decoders.
  • the output vector of the previous encoder is used as the input vector of the next encoder, and the output vector of the previous decoder is used as the input vector of the next encoder.
  • each encoder includes two sub-layers, which are the attention layer and the feed-forward neural network layer, and the connections between the sub-layers use LayerNorm and residual connections.
  • Each decoder includes three sub-layers, which are the first attention layer, the second attention layer and the feed-forward neural network layer, and the connections between the same sub-layers use LayerNorm and residual connections.
  • an encoder is used to generate a plurality of first text vector matrices corresponding to the context texts, and a decoder and a feed-forward neural network are used to extract and generate a reply text vector matrix corresponding to the question text.
  • the initial encoder when using the initial encoder to generate the first text vector matrix corresponding to multiple contextual texts, firstly perform word segmentation processing on multiple contextual texts to obtain each word segmentation contained in each contextual text, and then use the existing word2vec method , determine the embedding vectors corresponding to each word segment, and based on the embedding vectors corresponding to each word segment contained in each context text, form the embedding vector matrix corresponding to each context text, the number of rows of the embedding vector matrix represents the number of word segments, and the embedding vector matrix The number of columns represents the dimension of the embedding vector corresponding to each word segment, such as 256 dimensions. In this way, embedding vector matrices respectively corresponding to multiple contextual texts can be obtained in the above manner.
  • the embedding vector matrix corresponding to each contextual text is input to the attention layer in the initial encoder, and the first query corresponding to each contextual text can be obtained by making a corresponding linear change on the embedding vector matrix corresponding to the contextual text Matrix, the first key matrix and the first value matrix, based on the first query matrix, the first key matrix and the first value matrix, calculate the first text vector matrix corresponding to each context text, the specific formula is as follows:
  • the attention intensity matrix corresponding to each context text can be obtained, and then use d K to scale the attention intensity matrix, and input the scaled attention intensity matrix to the softmax layer for normalization processing, and obtain each The attention coefficient matrix corresponding to each context text, and then multiply the attention coefficient matrix with the first value matrix V to obtain the encoding vector matrix corresponding to each context text, further, input the encoding vector matrix to the initial encoder
  • the feedforward neural network layer in the process is processed, and the processed encoded vector matrix is input to the next initial encoder for processing.
  • the processing process of each initial encoder is the same as the above process, and the vector matrix output by the last initial encoder That is, the first text vector matrix, and thus the first text vector matrix corresponding to each context text can be obtained.
  • the context text in order to use the context text to generate the reply text corresponding to the question text, it is necessary to concatenate the first text vector matrices respectively corresponding to the multiple context texts, and use the concatenated first text vector matrix as the context text vector matrix, and then the The contextual text vector matrix and the embedding vector matrix corresponding to the question text are input to the initial decoder for decoding to obtain a second text vector matrix corresponding to the question text, so as to generate a reply text vector matrix based on the second text vector matrix.
  • the question text is segmented to obtain each word segment contained in the question text, and the existing word2vec method is used to determine the embedding vector corresponding to each word segment, and based on each word segment contained in the question text
  • the embedding vector corresponding to the word segmentation forms the embedding vector matrix corresponding to the question text
  • the embedding vector matrix corresponding to the question text is input to the first attention layer in the initial decoder for processing, and the third text corresponding to the question text is obtained
  • the processing process of the first attention layer in the initial decoder to the embedding vector matrix of the question text is exactly the same as that of the attention layer in the initial encoder, and will not be repeated here.
  • the obtained third text vector matrix is input to the second attention layer in the initial decoder for processing.
  • the obtained third text vector matrix is linearly transformed, and the linearly transformed first
  • the three-text vector matrix is used as the second query matrix of the question text, and then the concatenated context text vector matrix is linearly transformed, and the context text vectors after the linear transformation are respectively used as the second key matrix and the second value matrix of the question text, and then According to the obtained second query matrix, second key matrix and second value matrix, calculate the decoding vector matrix corresponding to the question text.
  • the decoding vector matrix output by the second attention layer is input to the feedforward neural network in the initial decoder for processing, and the processed decoding vector is input to the next initial decoder for decoding processing, and the last initial The vector matrix output by the decoder is the second text vector matrix.
  • the second text vector matrix finally output by the initial decoder is input to the first feed-forward neural network in the initial text vector generation model for processing to generate the question text A corresponding reply text vector matrix, so as to use the reply text vector matrix to generate a predicted reply text corresponding to the question text.
  • the initial topic vector extraction model includes multiple second feed-forward neural networks.
  • the topic vector parameters corresponding to each second feedforward neural network can be pre-initialized, and the dimensions corresponding to the topic vector parameters are the same as the number of columns corresponding to the first text vector matrix and the reply text vector matrix, and then each context
  • the first text vector matrix corresponding to the text is multiplied by multiple topic vector parameters, and the multiplication results are input to the corresponding second feedforward neural network for topic vector extraction to obtain multiple first topic vectors, and finally multiple The first topic vectors are added to obtain the contextual text topic vectors corresponding to each first text vector matrix.
  • the reply text vector matrix is multiplied by multiple topic vector parameters, and the multiplication result is input to the corresponding second front Feed the neural network to extract topic vectors to obtain multiple second topic vectors, and finally add multiple second topic vectors to obtain the reply text topic vector corresponding to the reply text vector matrix, specifically extract the context text topic vector and reply text topic vector See step 203 for the process.
  • the text generation model includes a text vector generation model and a topic vector extraction model
  • the text vector generation model includes an encoder, a decoder, and a first feedforward neural network
  • the topic vector extraction model includes a plurality of second feedforward neural networks and their corresponding
  • the topic vector parameters after the loss function is constructed, use the loss function to jointly perform initial encoder, initial decoder and first initial feed-forward neural network in the initial text vector generation model, as well as multiple The second feed-forward neural network and its corresponding topic vector parameters are trained to build a text generation model.
  • the application compared with the current way of using the deep learning model to generate the corresponding reply text, the application obtains the question text and multiple context texts in multiple rounds of dialogue; and uses the initial The text vector generation model generates the first text vector matrix corresponding to the plurality of context texts and the reply text vector matrix corresponding to the question text; at the same time, using the initial topic vector extraction model to extract the first text vector matrix respectively The corresponding context text topic vector and the reply text topic vector corresponding to the reply text vector matrix; and based on the context text topic vector and the reply text topic vector, a loss function is constructed; finally based on the loss function, the The initial text vector generation model and the initial topic vector extraction model are iteratively trained to construct a text generation model, thereby extracting the context topic vector and the reply text topic vector, and based on the context topic vector and the reply text topic vector, constructing a loss
  • the function trains the text generation model, which can make the topic vector of the reply text and the topic vector of the context as close as
  • the embodiment of the present application provides another training method of the text generation model, as shown in FIG. 2 ,
  • the methods include:
  • the reply text generation model includes a text vector generation model and a topic vector extraction model.
  • a text vector generation model In order to train the reply text generation model, it is necessary to initialize a text vector generation model in advance, and use the initial text vector generation model to generate multiple contextual texts respectively
  • the corresponding first text vector matrix and the reply text vector matrix corresponding to the question text, the specific generation process of the first text vector matrix and the reply text vector matrix are exactly the same as step 102, and will not be repeated here.
  • the initial topic vector extraction model includes a plurality of second initial feed-forward neural networks.
  • step 203 specifically includes: determining the topic vector parameters respectively corresponding to the plurality of second initial feedforward neural networks;
  • first initialize a topic vector parameter for each second initial feedforward neural network different second initial feedforward neural networks correspond to different topic vector parameters, and then combine each first text vector matrix with multiple topics Multiply the vector parameters to obtain multiple first multiplication results, and then input the multiple first multiplication results to the corresponding second initial feedforward neural network to extract topic vectors to obtain multiple first topic vectors, the specific formula as follows:
  • T i FFN m (softmax(MeanPooling(X i ) ⁇ tv m ))
  • X i represents the first text vector matrix
  • tv m represents the topic vector parameter
  • m 1...k
  • k is the number of topic vector parameters, which can be set according to actual business needs
  • T i represents the first topic vector
  • multiple first topic vectors can be obtained according to the above formula, and the multiple first topic vectors can be added to obtain the contextual text topic vector corresponding to each first text vector matrix.
  • the reply corresponding to the reply text vector matrix can be extracted A text topic vector to construct a loss function based on the context text topic vector and the reply text topic vector.
  • the reply text vector matrix is processed by the fully connected layer and the activation function respectively, and the word segmentation probability value corresponding to each word segmentation index position in the predicted reply text can be obtained, and the word segmentation probability value is mapped to the preset dictionary based on the word segmentation probability value, which can Obtain the reply participle at each participle index position, and splicing each reply participle to form a reply text.
  • the method includes: determining keywords corresponding to the predicted reply text from the plurality of context texts; inputting the reply text vector matrix to a fully connected layer for processing, and inputting the processed reply text vector matrix Process in the activation function to obtain the word segmentation probability value corresponding to each position index of the predicted reply text: based on the word segmentation probability value, determine the reply word segmentation at each position index, and determine whether there is The target word segmentation probability value greater than the preset probability value; if the target word segmentation probability value exists, the reply participle at the position index corresponding to the target word segmentation probability value is replaced by the keyword; according to the keyword and other Reply word segmentation at the position index to generate the predicted reply text.
  • keywords are determined from multiple contextual texts, and then the reply text vector matrix is respectively input into the fully connected layer and activation function for processing to obtain the word segmentation probability value corresponding to each word segmentation index position in the predicted reply text, through which
  • the word segmentation probability value and the preset dictionary can determine the reply word segmentation at each index position in the reply text, and further determine whether there is a target word segmentation probability value greater than the preset probability value in each word segmentation probability value, and if it exists, the target word segmentation
  • the reply participle indexed by the participle position corresponding to the probability value is replaced with the keyword, and then based on the keyword and other reply participle, the predicted reply text corresponding to the question text in the multi-round dialogue is formed.
  • a text loss function is constructed based on the predicted reply text and the real reply text corresponding to multiple rounds of dialogues, the specific formula is as follows:
  • L G represents the text loss function
  • P i represents the predicted reply participle at index position i
  • R i represents the real reply participle at index position i
  • the determining the keyword corresponding to the predicted reply text from the plurality of context texts includes: determining the longest context text among the plurality of context texts; The corresponding first text vector matrix and the first text vector matrix corresponding to other contextual texts respectively calculate the similarity matrix between the longest contextual text and the other contextual texts; horizontally splicing the calculated similarity matrices , and sum the similarity matrix after splicing by row to obtain the summation result corresponding to each row in the similarity matrix after splicing; determine the maximum summation result from the summation result corresponding to each row, and determine the summation result The row index corresponding to the maximum summation result; and the word segmentation at the row index in the longest context text is determined as the keyword.
  • the longest context text among multiple context texts is used as the target text that may contain keywords.
  • a context text may also be randomly selected as the target text that may contain keywords , or take the first sentence text in multiple context texts as the target text that may contain key dictionaries, and then calculate the target text and other
  • the similarity matrix between the context texts, and the calculated multiple similarity matrices are horizontally spliced, and then the spliced similarity matrix is summed by row, and the maximum summation result and its corresponding row index are determined, and The participle corresponding to the row index in the target text is determined as the target participle.
  • keywords in the context text can be locked in the manner described above, so that the keywords can be generated in the reply text.
  • the initial encoder, the initial decoder, and the first initial front Feed-forward neural network, and multiple second feed-forward neural networks and their corresponding topic vector parameters are trained to build a text generation model.
  • the application compared with the current way of using the deep learning model to generate the corresponding reply text, the application obtains the question text and multiple context texts in multiple rounds of dialogue; and uses the initial The text vector generation model generates the first text vector matrix corresponding to the plurality of context texts and the reply text vector matrix corresponding to the question text; at the same time, using the initial topic vector extraction model to extract the first text vector matrix respectively The corresponding context text topic vector and the reply text topic vector corresponding to the reply text vector matrix; and based on the context text topic vector and the reply text topic vector, a loss function is constructed; finally based on the loss function, the The initial text vector generation model and the initial topic vector extraction model are iteratively trained to construct a text generation model, thereby extracting the context topic vector and the reply text topic vector, and based on the context topic vector and the reply text topic vector, constructing a loss
  • the function trains the text generation model, which can make the topic vector of the reply text and the topic vector of the context as close as
  • an embodiment of the present application provides a text generation model training device.
  • the device includes: an acquisition unit 31, a generation unit 32, an extraction unit 33, and a construction unit 34 and training unit 35.
  • the obtaining unit 31 may be used to obtain question texts and multiple context texts in multiple rounds of dialogue.
  • the generation unit 32 may be configured to use an initial text vector generation model to generate a first text vector matrix corresponding to the plurality of context texts and a reply text vector matrix corresponding to the question text.
  • the extraction unit 33 may be configured to use an initial topic vector extraction model to respectively extract context text topic vectors corresponding to the first text vector matrix and reply text topic vectors corresponding to the reply text vector matrix.
  • the construction unit 34 may be configured to construct a loss function based on the context text topic vector and the reply text topic vector.
  • the training unit 35 may be configured to iteratively train the initial text vector generation model and the initial topic vector extraction model based on the loss function to construct a text generation model.
  • the generating unit 32 in order to generate the first text vector matrix and the reply text vector matrix, the generating unit 32, as shown in FIG.
  • the encoding module 321 may be configured to input the embedding vector matrices respectively corresponding to the plurality of contextual texts into the initial encoder for encoding to obtain the first text vector matrices respectively corresponding to the plurality of contextual texts.
  • the splicing module 322 may be configured to splice multiple first text vector matrices to obtain contextual text vector matrices corresponding to the multiple rounds of dialogue.
  • the decoding module 323 may be configured to input the contextual text vector matrix and the embedding vector corresponding to the question text into the initial decoder for decoding to obtain a second text vector matrix corresponding to the question text.
  • the generating module 324 may be configured to input the second text vector matrix into the first initial feed-forward neural network to obtain a reply text vector matrix corresponding to the question text.
  • the encoding module 321 includes: a transformation submodule, a multiplication submodule and a first processing submodule.
  • the transformation sub-module can be used to perform corresponding linear transformations on the embedding vectors respectively corresponding to the plurality of contextual texts to obtain the first query matrix, the first key matrix and the first value corresponding to the plurality of contextual texts respectively matrix.
  • the multiplication sub-module can be used to transpose the first key matrix, and multiply the transposed first key matrix with the first query matrix to obtain the context texts corresponding to the multiple context texts respectively.
  • the first processing sub-module may be configured to input the attention intensity matrix to the softmax layer in the initial encoder for normalization processing, to obtain attention coefficient matrices corresponding to the plurality of contextual texts respectively.
  • the multiplication sub-module may also be configured to multiply the attention coefficient matrix and the first value matrix to obtain first text vector matrices respectively corresponding to the plurality of contextual texts.
  • the decoding module 323 includes: an extraction submodule, a first determination submodule and a calculation submodule.
  • the extraction sub-module may be configured to input the embedding vector corresponding to the question text to the first attention layer for text feature extraction, and obtain a third text vector matrix corresponding to the question text.
  • the first determining submodule may be configured to determine a second query matrix corresponding to the question text according to the third text vector matrix.
  • the first determining submodule may also be configured to respectively determine a second key matrix and a second value matrix corresponding to the question text according to the context text vector matrix.
  • the calculation submodule may be configured to calculate a second text vector matrix corresponding to the question text according to the second query matrix, the second key matrix and the second value matrix.
  • the initial topic vector extraction model includes multiple second initial feedforward neural networks
  • the extraction unit 33 includes: a determination module 331 , a multiplication module 332 , an extraction module 333 and an addition module 334 .
  • the determining module 331 may be configured to determine topic vector parameters respectively corresponding to the plurality of second initial feedforward neural networks.
  • the multiplication module 332 may be configured to multiply the first text vector matrix and the reply text vector matrix by the plurality of topic vector parameters to obtain a plurality of the first text vector matrices corresponding to the first text vector matrix. A multiplication result and multiple second multiplication results corresponding to the reply text vector matrix.
  • the extraction module 333 can be configured to input the plurality of first multiplication results and the plurality of second multiplication results into the corresponding second initial feedforward neural network to extract topic vectors, and obtain the extracted A plurality of first topic vectors and a plurality of second topic vectors.
  • the adding module 334 may be configured to add the plurality of extracted first topic vectors to obtain a contextual text topic vector corresponding to the first text vector matrix.
  • the adding module 334 may also be configured to add the plurality of extracted second topic vectors to obtain a reply text topic vector corresponding to the reply text vector matrix.
  • the loss function includes a similarity loss function and a text loss function
  • the construction unit 34 includes: a construction module 341 and a prediction module 342 .
  • the construction module 341 may be configured to calculate similarities between multiple context text topic vectors and reply text topic vectors, and construct the similarity loss function based on the calculated multiple similarities.
  • the prediction module 342 may be configured to predict the predicted reply text corresponding to the multiple rounds of dialogues based on the reply text vector matrix.
  • the construction module 341 may also be configured to obtain the real reply texts corresponding to the multiple rounds of dialogues, and construct the text loss function based on the real reply texts and the predicted reply texts.
  • the prediction module 342 includes: a second determination submodule, a second processing submodule, a determination submodule, a replacement submodule and a generation submodule.
  • the second determining submodule may be configured to determine keywords corresponding to the predicted reply text from the plurality of contextual texts.
  • the second processing submodule can be used to input the reply text vector matrix to the fully connected layer for processing, and input the processed reply text vector matrix to an activation function for processing to obtain the predicted reply text
  • the determination block can be used to determine the reply word at each position index based on the word segmentation probability value, and determine whether there is a target word segmentation probability value greater than a preset probability value among each word segmentation probability value.
  • the replacing submodule may be configured to replace the reply participle at the position index corresponding to the target participle probability value with the keyword if the target participle probability value exists.
  • the generation sub-module may be used to generate the predicted reply text according to the keyword and reply word segmentation at other position indexes.
  • the second determination submodule can be specifically configured to determine the longest context text among the plurality of context texts; according to the first text vector matrix corresponding to the longest context text and the first text vector matrix corresponding to other context texts A text vector matrix, respectively calculating similarity matrices between the longest context text and the other context texts; horizontally splicing the calculated similarity matrices, and summing the spliced similarity matrices by rows, Obtain the summation result corresponding to each row in the similarity matrix after the splicing; determine the maximum summation result from the summation result corresponding to each row, and determine the row index corresponding to the maximum summation result; The word segmentation at the row index in the long context text is determined as the keyword.
  • the embodiment of the present application also provides a computer-readable storage medium
  • the computer-readable storage medium may be non-volatile or volatile, on which There are computer-readable instructions, and when the program is executed by the processor, the following steps are implemented: obtaining question texts and multiple context texts in multiple rounds of dialogue; using an initial text vector generation model to generate first texts respectively corresponding to the multiple context texts vector matrix and the reply text vector matrix corresponding to the question text; using the initial topic vector extraction model to extract the context text topic vector corresponding to the first text vector matrix and the reply text topic vector corresponding to the reply text vector matrix; based on The context text topic vector and the reply text topic vector construct a loss function; based on the loss function, iteratively trains the initial text vector generation model and the initial topic vector extraction model to construct a text generation model.
  • the embodiment of the present application also provides a physical structure diagram of a computer device, as shown in FIG. 5 , the computer device includes: a processor 51, A memory 52, and computer-readable instructions stored on the memory 52 and operable on the processor, wherein the memory 52 and the processor 51 are both arranged on the bus 53, and the processor 51 implements the following steps when executing the program : Obtain question text and multiple context texts in multiple rounds of dialogue; use the initial text vector generation model to generate the first text vector matrix corresponding to the multiple context texts and the reply text vector matrix corresponding to the question text; use the initial The topic vector extraction model respectively extracts the context text topic vector corresponding to the first text vector matrix and the reply text topic vector corresponding to the reply text vector matrix; based on the context text topic vector and the reply text topic vector, a loss is constructed function; based on the loss function, iteratively trains the initial text vector generation model and the initial topic vector extraction model to
  • the question text and multiple context texts in multiple rounds of dialogue can be obtained; and the initial text vector generation model is used to generate the first text vector matrix corresponding to the multiple context texts and the corresponding first text vector matrix of the question text Reply text vector matrix; at the same time, use the initial topic vector extraction model to extract the context text topic vector corresponding to the first text vector matrix and the reply text topic vector corresponding to the reply text vector matrix; and based on the context
  • the text topic vector and the reply text topic vector construct a loss function; finally, based on the loss function, iteratively trains the initial text vector generation model and the initial topic vector extraction model to construct a text generation model, thus by Extract the context topic vector and the reply text topic vector, and based on the context topic vector and the reply text topic vector, construct a loss function to train the text generation model, which can make the reply text topic vector and the context topic vector as close as possible, thus ensuring
  • the generated reply text is deeply related to the topic of the contextual dialogue, so that the generated reply text fits the overall logic of the multi
  • each module or each step of the above-mentioned application can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed in a network composed of multiple computing devices Alternatively, they may be implemented in program code executable by a computing device so that they may be stored in a storage device to be executed by a computing device, and in some cases in an order different from that shown here
  • the steps shown or described are carried out, or they are separately fabricated into individual integrated circuit modules, or multiple modules or steps among them are fabricated into a single integrated circuit module for implementation.
  • the present application is not limited to any specific combination of hardware and software.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Evolutionary Computation (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Databases & Information Systems (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Software Systems (AREA)
  • Molecular Biology (AREA)
  • Biophysics (AREA)
  • Biomedical Technology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Machine Translation (AREA)

Abstract

一种文本生成模型的训练方法、装置、存储介质及计算机设备,涉及人工智能技术领域中的神经网络模型。其中方法包括:获取多轮对话中的问题文本和多个上下文文本(101);利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵(102);利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量(103);基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数(104);基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型(105)。

Description

文本生成模型的训练方法、装置、存储介质及计算机设备
本申请要求与2021年12月15日提交中国专利局、申请号为202111534333.9申请名称为“文本生成模型的训练方法、装置、存储介质及计算机设备”的中国专利申请的优先权,其全部内容通过引用结合在申请中。
技术领域
本申请涉及机器学习技术领域,尤其是涉及一种文本生成模型的训练方法、装置、存储介质及计算机设备。
背景技术
在自然语言处理中,多轮对话始终是研究的热点,而如何准确、有效地生成回复文本对多轮对话的研究有重要意义。
目前,通常是基于多轮对话中对上下文的理解,利用深度学习模型,生成相应的回复文本。然而,发明人意识到,这种方式在训练深度学习模型的过程中,并没有考虑生成的回复文本与多轮对话中的上下文对话主题是否深层次相关,进而导致利用该深度学习模型生成的回复文本偏离多轮对话的整体逻辑,无法保证回复文本的生成精度。
发明内容
本申请提供了一种文本生成模型的训练方法、装置、存储介质及计算机设备,主要在于能够保证生成的回复本文与上下文对话主题深层次相关,从而能够使生成的回复文本贴合多轮对话的整体逻辑,提高回复文本的生成精度。
根据本申请的第一个方面,提供一种文本生成模型的训练方法,包括:
获取多轮对话中的问题文本和多个上下文文本;
利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
根据本申请的第二个方面,提供一种文本生成模型的训练装置,包括:
获取单元,用于获取多轮对话中的问题文本和多个上下文文本;
生成单元,用于利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
提取单元,用于利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
构建单元,用于基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
训练单元,用于基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
根据本申请的第三个方面,提供一种计算机可读存储介质,其上存储有计算机可读指令,该程序被处理器执行时实现以下步骤:
获取多轮对话中的问题文本和多个上下文文本;
利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵 和所述问题文本对应的回复文本向量矩阵;
利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
根据本申请的第四个方面,提供一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机可读指令,所述处理器执行所述程序时实现以下步骤:
获取多轮对话中的问题文本和多个上下文文本;
利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
根据本申请提供的一种文本生成模型的训练方法、装置、存储介质及计算机设备,与目前利用深度学习模型生成相应的回复文本的方式相比,本申请通过获取多轮对话中的问题文本和多个上下文文本;并利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;与此同时,利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;并基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;最终基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型,由此通过提取上下文主题向量和回复文本主题向量,并基于该上下文本主题向量和回复文本主题向量,构建损失函数对文本生成模型进行训练,能够使回复文本主题向量和上下文主题向量尽可能相近,从而能够保证生成的回复文本与上下文对话主题深层次相关,使生成的回复文本贴合多轮对话的整体逻辑,进而提高了多轮对话中回复文本的生成精度。
附图说明
此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。在附图中:
图1示出了本申请实施例提供的一种文本生成模型的训练方法流程图;
图2示出了本申请实施例提供的另一种文本生成模型的训练方法流程图;
图3示出了本申请实施例提供的一种文本生成模型的训练装置结构示意图;
图4示出了本申请实施例提供的另一种文本生成模型的训练装置结构示意图;
图5示出了本申请实施例提供的一种计算机设备的实体结构示意图。
具体实施方式
下文中将参考附图并结合实施例来详细说明本申请。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
目前,在训练深度学习模型的过程中,并没有考虑生成的回复文本与多轮对话中的上下文对话主题是否深层次相关,进而导致利用该深度学习模型生成的回复文本偏离多轮对话的整体逻辑,无法保证回复文本的生成精度。
为了解决上述问题,本申请实施例提供了一种文本生成模型的训练方法,如图1所示,所述方法包括:
101、获取多轮对话中的问题文本和多个上下文文本。
其中,多轮对话中至少包括三个语句文本,将最后一个语句文本作为问题文本,其他语句文本作为上下文文本。为了克服现有技术中生成的回复文本与上下文对话主题无法深层次相关,进而导致生成的回复文本偏离多轮对话整体逻辑的缺陷,本申请实施例,在训练文本生成模型的过程中,能够提取上下文主题向量和回复文本主题向量,并利用该上下文主题向量和回复文本主题向量,构建损失函数,基于该损失函数对文本生成模型进行训练,从而能够保证利用该文本生成模型生成的回复文本能够与上下文对话主题深层次相关,且贴合多轮对话的整体逻辑。本申请实施例主要应用于多轮对话中训练回复文本生成模型的场景。本申请实施例的执行主体为能够对回复文本生成模型进行训练的装置或者设备,具体可以设置在服务器一侧。
对于本申请实施例,为了训练多轮对话的回复文本生成模型,需要预先收集多轮对话中的样本语句,在一个多轮对话中至少包括三个样本语句,将最后一个样本语句作为问题文本,同时将其他样本语句作为上下文文本,在对文本生成模型进行训练的过程,收集的问题文本对应的真实回复文本是已知的。例如,多轮对话中包括四个样本语句,样本语句1为“我们出去吃东西吧!”,样本语句2为“今天天气不好,你想去哪吃啊?”,样本语句3为“我知道一家刚开业的店,可以坐地铁去吃饭。”,样本语句4为“这样好啊,可以不被雨淋。”,在训练文本生成模型的过程中,将上述样本语句1、样本语句2和样本语句3作为上下文文本,同时将样本语句4(最后一个样本语句)作为问题文本,之后基于该上下文文本,预测问题文本对应的预测回复文本,同时提取回复文本主题向量和上下文文本主题向量,最终基于该预测回复文本、真实回复文本、回复文本主题向量和上下文文本主题向量,构建损失函数,基于该损失函数训练文本生成模型。
102、利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵。
其中,所述初始文本向量生成模型包括初始编码器、初始解码器和第一初始前馈神经网络。对于本申请实施例,在训练文本生成模型的过程中,为了生成多个上下文文本分别对应的第一文本向量矩阵和问题文本对应的回复文本向量矩阵,步骤102具体包括:将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵;将多个所述第一文本向量矩阵进行拼接,得到所述多轮对话对应的上下文文本向量矩阵;将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至所述初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵;将所述第二文本向量矩阵输入至所述第一初始前馈神经网络中,得到所述问题文本对应的回复文本向量矩阵。
进一步地,所述将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵,包括:对所述多个上下文文本分别对应的嵌入向量进行相应的线性变换,得到所述多个上下文文本分别对应的第一查询矩阵、第一键矩阵和第一值矩阵;对所述第一键矩阵进行转置处理,将转置后的第一键矩阵与所述第一查询矩阵相乘,得到所述多个上下文文本分别对应的注意力强度矩阵;将所述注意力强度矩阵输入至所述初始编码器中的softmax层进行归一化处理,得到所述多个上下文文本分别对应的注意力系数矩阵;将所述注意力系数矩阵与所述第一值矩阵相乘,得到所述多个上下文文本分别对应的第一文本向量矩阵。与此同时,所述初始解码器包括第一注意力层和第二注意力层,所述将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵,包括:将所述问题文本对应的嵌入向量输入至所述第一注意力层进行文本特征提取,得到所述问题文本对应的第三文本向量矩阵;根据所述第三文本向量矩阵,确定所述问题文本对应的第二查询矩阵;根据所述所述上下文文本向量矩阵,分别确定所述问 题文本对应的第二键矩阵和第二值矩阵;根据所述第二查询矩阵、所述第二键矩阵和所述第二值矩阵,计算所述问题文本对应的第二文本向量矩阵。
具体地,本申请实施例的文本生成模型主要包括文本向量生成模型和主题向量提取模型,该文本向量生成模型主要由前馈神经网络,transformer模型中的编码器和解码器组成,文本向量生成模型中共包括6个首尾相连的编码器和6个首尾相连的解码器,上一个编码器的输出向量作为下一个编码器的输入向量,同样上一个解码器的输出向量作为下一个编码器的输入向量,每个编码器包括两个子层,分别是注意力层和前馈神经网络层,子层之间的连接使用LayerNorm和残差连接,每个解码器包括三个子层,分别是第一注意力层、第二注意力层和前馈神经网络层,同样子层之间的连接使用LayerNorm和残差连接。在本申请实施例中,利用编码器生成多个上下文文本分别对应的第一文本向量矩阵,利用解码器和前馈神经网络提取生成问题文本对应的回复文本向量矩阵。
具体地,在利用初始编码器生成多个上下文文本分别对应的第一文本向量矩阵时,首先对多个上下文文本进行分词处理,得到每个上下文文本包含的各个分词,之后利用现有的word2vec方式,确定各个分词对应的嵌入向量,并基于每个上下文文本中包含的各个分词对应的嵌入向量,组成每个上下文本对应的嵌入向量矩阵,嵌入向量矩阵的行数代表分词的数量,嵌入向量矩阵的列数代表每个分词对应的嵌入向量的维度,如256维度。由此按照上述方式能够得到多个上下文文本分别对应的嵌入向量矩阵。
进一步地,将每个上下文文本对应的嵌入向量矩阵输入至初始编码器中的注意力层,通过对上下文文本对应的嵌入向量矩阵进行相应的线性变化,能够得到每个上下文文本对应的第一查询矩阵、第一键矩阵和第一值矩阵,基于该第一查询矩阵、第一键矩阵和第一值矩阵,计算每个上下文文本对应的第一文本向量矩阵,具体公式如下:
Figure PCTCN2022089734-appb-000001
其中,Q为第一查询矩阵,K为第一键矩阵,V为第一值矩阵,d K为第一键矩阵的列数,将转置后的第一键矩阵K与第一查询矩阵Q相乘,能够得到每个上下文文本对应的注意力强度矩阵,之后利用d K对注意力强度矩阵进行尺度缩放,将尺度缩放后的注意力强度矩阵输入至softmax层进行归一化处理,得到每个上下文文本对应的注意力系数矩阵,接着将该注意力系数矩阵与第一值矩阵V相乘,得到每个上下文文本对应的编码向量矩阵,进一步地,将该编码向量矩阵输入至初始编码器中的前馈神经网络层进行处理,并将处理后的编码向量矩阵输入至下一个初始编码器进行处理,每个初始编码器的处理过程与上述过程相同,最后一个初始编码器输出的向量矩阵即为第一文本向量矩阵,由此能够得到每个上下文文本对应的第一文本向量矩阵。
进一步地,为了利用上下文文本生成问题文本对应的回复文本,需要将多个上下文文本分别对应的第一文本向量矩阵进行拼接,将拼接后的第一文本向量矩阵作为上下文文本向量矩阵,之后将该上下文文本向量矩阵和问题文本对应的嵌入向量矩阵一同输入至初始解码器中进行解码,得到问题文本对应的第二文本向量矩阵,以便基于该第二文本向量矩阵,生成回复文本向量矩阵。在利用初始解码器进行解码时,首先对问题文本进行分词处理,得到问题文本中包含的各个分词,并利用现有的word2vec方式,确定各个分词对应的嵌入向量,并基于问题文本中包含的各个分词对应的嵌入向量,组成问题文本对应的嵌入向量矩阵,进一步地,将该问题文本对应的嵌入向量矩阵输入至初始解码器中的第一注意力层进行处理,得到问题文本对应的第三文本向量矩阵,初始解码器中的第一注意力层对问题文本的嵌入向量矩阵的处理过程与初始编码器中的注意力层的处理过程完全相同,在此不再赘述。
进一步地,将得到的第三文本向量矩阵输入至初始解码器中的第二注意力层进行处理,具体处理时,首先对得到的第三文本向量矩阵进行线性变换,并将线性变化后的第三文本 向量矩阵作为问题文本的第二查询矩阵,之后对拼接的上下文文本向量矩阵进行线性变换,并将线性变换后的上下文文本向量分别作为问题文本的第二键矩阵和第二值矩阵,接着根据得到的第二查询矩阵、第二键矩阵和第二值矩阵,计算问题文本对应的解码向量矩阵,需要说明的是,利用第二查询矩阵、第二键矩阵和第二值矩阵,计算问题文本对应的解码向量矩阵的具体过程与上述利用第一查询矩阵、第一键矩阵和第一值矩阵,计算每个上下文文本对应的编码向量矩阵的过程完全相同,在此不再赘述。进一步地,将第二注意力层输出的解码向量矩阵输入至初始解码器中的前馈神经网络进行处理,并将处理后的解码向量输入至下一个初始解码器中进行解码处理,最后一个初始解码器输出的向量矩阵即为第二文本向量矩阵,进一步地,将初始解码器最终输出的第二文本向量矩阵输入至初始文本向量生成模型中的第一前馈神经网络进行处理,生成问题文本对应的回复文本向量矩阵,以便利用该回复文本向量矩阵,生成问题文本对应的预测回复文本。
103、利用初始主题量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量。
其中,初始主题向量提取模型包括多个第二前馈神经网络。对于本申请实施例,为了保证生成的回复文本与上下文本主题深层次相关,需要利用初始主题向量提取模型分别提取第一文本向量矩阵对应的上下文主题向量和回复文本向量矩阵对应的回复文本主题向量,具体地,可以预先初始化每个第二前馈神经网络对应的主题向量参数,该主题向量参数对应的维度与第一文本向量矩阵和回复文本向量矩阵对应的列数相同,之后将每个上下文文本对应的第一文本向量矩阵分别与多个主题向量参数相乘,并将相乘结果输入至对应的第二前馈神经网络进行主题向量提取,得到多个第一主题向量,最终将多个第一主题向量相加,得到每个第一文本向量矩阵对应的上下文文本主题向量,同理将回复文本向量矩阵与多个主题向量参数相乘,并将相乘结果输入至对应的第二前馈神经网络进行主题向量提取,得到多个第二主题向量,最终将多个第二主题向量相加,得到回复文本向量矩阵对应的回复文本主题向量,具体提取上下文文本主题向量和回复文本主题向量的过程见步骤203。
104、基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数。
对于本申请实施例,在提取上下文文本主题向量和回复文本主题向量之后,分别计算多个上下文文本主题向量与回复文本主题向量之间的余弦相似度,并将计算的各个余弦相似度相加,构建损失函数。
105、基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
其中,文本生成模型包括文本向量生成模型和主题向量提取模型,文本向量生成模型包括编码器、解码器和第一前馈神经网络,主题向量提取模型包括多个第二前馈神经网络及其对应的主题向量参数,对于本申请实施例,在构建完成损失函数之后,利用该损失函数共同对初始文本向量生成模型中的初始编码器、初始解码器和第一初始前馈神经网络,以及多个第二前馈神经网络及其对应的主题向量参数进行训练,构建文本生成模型。
根据本申请提供的一种文本生成模型的训练方法,与目前利用深度学习模型生成相应的回复文本的方式相比,本申请通过获取多轮对话中的问题文本和多个上下文文本;并利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;与此同时,利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;并基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;最终基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型,由此通过提取上下文主题向量和回复文本主题向量,并基于该上下文本主题向量和回复文本主题向量,构建损失函数对文本生成模型进行训练, 能够使回复文本主题向量和上下文主题向量尽可能相近,从而能够保证生成的回复文本与上下文对话主题深层次相关,使生成的回复文本贴合多轮对话的整体逻辑,进而提高了多轮对话中回复文本的生成精度。
进一步地,为了更好的说明上述对文本生成模型的训练过程,作为对上述实施例的细化和扩展,本申请实施例提供了另一种文本生成模型的训练方法,如图2所示,所述方法包括:
201、获取多轮对话中的问题文本和多个上下文文本。
对于本申请实施例,为了对多轮对话的回复文本生成模型进行训练,需要预先收集多轮对话中的样本语句,并将样本语句中的最后一个样本语句作为问题文本,同时将其他样本语句作为上下文文本。
202、利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵。
对于本申请实施例,回复文本生成模型包括文本向量生成模型和主题向量提取模型,为了训练回复文本生成模型,需要预先初始化一个文本向量生成模型,并利用初始文本向量生成模型生成多个上下文文本分别对应的第一文本向量矩阵和问题文本对应的回复文本向量矩阵,第一文本向量矩阵和回复文本向量矩阵的具体生成过程与步骤102完全相同,在此不再赘述。
203、利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量。
其中,所述初始主题向量提取模型包括多个第二初始前馈神经网络。对于本申请实施例,为了提取上下文文本主题向量和回复文本主题向量,步骤203具体包括:确定所述多个第二初始前馈神经网络分别对应的主题向量参数;
将所述第一文本向量矩阵和所述回复文本向量矩阵分别与所述多个主题向量参数相乘,得到所述第一文本向量矩阵对应的多个第一相乘结果和所述回复文本向量矩阵对应的多个第二相乘结果;将所述多个第一相乘结果和所述多个第二相乘结果分别输入至相应的第二初始前馈神经网络中进行主题向量提取,得到提取的多个第一主题向量和多个第二主题向量;将提取的所述多个第一主题向量相加,得到所述第一文本向量矩阵对应的上下文文本主题向量;
将提取的所述多个第二主题向量相加,得到所述回复文本向量矩阵对应的回复文本主题向量。
具体地,首先为每个第二初始前馈神经网络初始化一个主题向量参数,不同的第二初始前馈神经网络对应的主题向量参数不同,之后将每个第一文本向量矩阵分别与多个主题向量参数相乘,得到多个第一相乘结果,接着将多个第一相乘结果分别输入至对应的第二初始前馈神经网络进行主题向量提取,得到多个第一主题向量,具体公式如下:
T i=FFN m(softmax(MeanPooling(X i)·tv m))
其中,X i代表第一文本向量矩阵,tv m代表主题向量参数,m=1…k,k为主题向量参数的数量,具体可以根据实际业务需求进行设定,T i代表第一主题向量,由此按照上述公式能够得到多个第一主题向量,将多个第一主题向量相加,得到每个第一文本向量矩阵对应的上下文文本主题向量,同理可以提取回复文本向量矩阵对应的回复文本主题向量,以便基于该上下文文本主题向量和回复文本主题向量,构建损失函数。
204、分别计算多个所述上下文文本主题向量与所述回复文本主题向量之间的相似度,基于计算的多个相似度,构建所述相似度损失函数。
对于本申请实施例,在得到多个第一文本向量矩阵分别对应的上下文文本主题向量和回复文本向量矩阵对应的回复文本主题向量之后,分别计算每个上下文文本主题向量与回 复文本主题向量之间的余弦相似度,并将计算的各个余弦相似度相加,构建相似度损失函数。
205、基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本,并获取所述多轮对话对应的真实回复文本,基于所述真实回复文本和所述预测回复文本,构建所述文本损失函数。
对于本申请实施例,回复文本向量矩阵分别经过全连接层和激活函数的处理,能够得到预测回复文本中各个分词索引位置对应的分词概率值,基于该分词概率值向预设词典做映射,能够得到各个分词索引位置处的回复分词,将各个回复分词拼接起来,便组成回复文本。在此基础上,为了保证生成的回复文本尽可能包含上下文文本中的关键词,避免生成的回复文本是通用回复,如“是的”、“好的”,本申请实施例,通过锁定上下文文本中的关键词,并在生成预测回复文本的过程中,将相应位置处理的回复分词替换成该关键词,能够保证回复文本中尽可能包含关键词,避免回复文本仅仅是通用回答,基于此,所述方法包括:从所述多个上下文文本中确定所述预测回复文本对应的关键词;将所述回复文本向量矩阵输入至全连接层进行处理,并将经过处理后的回复文本向量矩阵输入至激活函数中进行处理,得到所述预测回复文本的各个位置索引对应的分词概率值:基于所述分词概率值,确定所述各个位置索引处的回复分词,并判定各个分词概率值中是否存在大于预设概率值的目标分词概率值;若存在所述目标分词概率值,则将所述目标分词概率值对应的位置索引处的回复分词替换成所述关键词;根据所述关键词和其他位置索引处的回复分词,生成所述预测回复文本。
具体地,首先从多个上下文文本中确定关键词,之后将回复文本向量矩阵分别输入至全连接层和激活函数中进行处理,得到预测回复文本中各个分词索引位置对应的分词概率值,通过该分词概率值和预设词典,能够确定回复文本中各个索引位置处的回复分词,进一步地,判定各个分词概率值中是否存在大于预设概率值的目标分词概率值,如果存在,则将目标分词概率值对应的分词位置索引出的回复分词替换成该关键词,进而基于该关键词和其他回复分词,组成多轮对话中问题文本对应的预测回复文本。
进一步地,在得到预测回复文本之后,基于该预测回复文本和多轮对话对应的真实回复文本,构建文本损失函数,具体公式如下:
Figure PCTCN2022089734-appb-000002
其中,L G代表文本损失函数,P i代表索引位置i处的预测回复分词,R i代表索引位置i处的真实回复分词,L代表预测回复文本的长度,即预测回复文本包含的回复分词数量,例如,真实回复文本为“好/那/我们/现在/去/吃饭”,预测回复文本为“好/那/我们/现在/走/呀”,预测回复文本和真实回复文本中共包含6个回复分词,预测回复文本中最后两个回复分词与真实回复文本不同,因此可以计算出L G=4/6。
在具体应用场景中,所述从所述多个上下文文本中确定所述预测回复文本对应的关键词,包括:确定所述多个上下文文本中的最长上下文文本;根据所述最长上下文文本对应的第一文本向量矩阵和其他上下文文本对应的第一文本向量矩阵,分别计算所述最长上下文文本与所述其他上下文文本之间的相似度矩阵;将计算的各个相似度矩阵进行横向拼接,并对拼接后的相似度矩阵按行求和,得到所述拼接后的相似度矩阵中各行对应的求和结果;从所述各行对应的求和结果中确定最大求和结果,并确定所述最大求和结果对应的行索引;将所述最长上下文文本中所述行索引处的分词确定为所述关键词。
具体地,首先将多个上下文文本中的最长上下文文本作为可能包含关键词的目标文本,需要说明的是,在本申请实施例中还可以随机选择一个上下文文本作为可能包含关键词的目标文本,或者将多个上下文文本中的首句文本作为可能包含关键词典的目标文本,之后根据目标文本对应的第一文本向量矩阵和其他上下文文本对应的第一文本向量矩阵,分别 计算目标文本与其他上下文文本之间的相似度矩阵,并将计算的多个相似度矩阵进行横向拼接,接着对拼接后的相似度矩阵按行求和,并确定最大求和结果及其对应的行索引,并将目标文本中该行索引对应的分词确定为目标分词。由此按照上述方式能够锁定上下文文本中的关键词,以便将该关键词生成在回复文本中。
206、基于所述相似度损失函数和所述文本损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
对于本申请实施例,在构建完成相似度损失函数和文本损失函数之后,利用该相似度损失函数和文本损失函数共同对初始文本向量生成模型中的初始编码器、初始解码器和第一初始前馈神经网络,以及多个第二前馈神经网络及其对应的主题向量参数进行训练,构建文本生成模型。
根据本申请提供的一种文本生成模型的训练方法,与目前利用深度学习模型生成相应的回复文本的方式相比,本申请通过获取多轮对话中的问题文本和多个上下文文本;并利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;与此同时,利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;并基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;最终基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型,由此通过提取上下文主题向量和回复文本主题向量,并基于该上下文本主题向量和回复文本主题向量,构建损失函数对文本生成模型进行训练,能够使回复文本主题向量和上下文主题向量尽可能相近,从而能够保证生成的回复文本与上下文对话主题深层次相关,使生成的回复文本贴合多轮对话的整体逻辑,进而提高了多轮对话中回复文本的生成精度。
进一步地,作为图1的具体实现,本申请实施例提供了一种文本生成模型的训练装置,如图3所示,所述装置包括:获取单元31、生成单元32、提取单元33、构建单元34和训练单元35。
所述获取单元31,可以用于获取多轮对话中的问题文本和多个上下文文本。
所述生成单元32,可以用于利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵。
所述提取单元33,可以用于利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量。
所述构建单元34,可以用于基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数。
所述训练单元35,可以用于基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
在具体应用场景中,为了生成第一文本向量矩阵和回复文本向量矩阵,所述生成单元32,如图4所示,包括:编码模块321、拼接模块322、解码模块323和生成模块324。
所述编码模块321,可以用于将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵。
所述拼接模块322,可以用于将多个所述第一文本向量矩阵进行拼接,得到所述多轮对话对应的上下文文本向量矩阵。
所述解码模块323,可以用于将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至所述初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵。
所述生成模块324,可以用于将所述第二文本向量矩阵输入至所述第一初始前馈神经网络中,得到所述问题文本对应的回复文本向量矩阵。
进一步地,为了生成上下文文本对应的第一文本向量矩阵,所述编码模块321,包括: 变换子模块、相乘子模块和第一处理子模块。
所述变换子模块,可以用于对所述多个上下文文本分别对应的嵌入向量进行相应的线性变换,得到所述多个上下文文本分别对应的第一查询矩阵、第一键矩阵和第一值矩阵。
所述相乘子模块,可以用于对所述第一键矩阵进行转置处理,将转置后的第一键矩阵与所述第一查询矩阵相乘,得到所述多个上下文文本分别对应的注意力强度矩阵。
所述第一处理子模块,可以用于将所述注意力强度矩阵输入至所述初始编码器中的softmax层进行归一化处理,得到所述多个上下文文本分别对应的注意力系数矩阵。
所述相乘子模块,还可以用于将所述注意力系数矩阵与所述第一值矩阵相乘,得到所述多个上下文文本分别对应的第一文本向量矩阵。
进一步地,为了生成问题文本对应的第二文本向量矩阵,所述解码模块323,包括:提取子模块、第一确定子模块和计算子模块。
所述提取子模块,可以用于将所述问题文本对应的嵌入向量输入至所述第一注意力层进行文本特征提取,得到所述问题文本对应的第三文本向量矩阵。
所述第一确定子模块,可以用于根据所述第三文本向量矩阵,确定所述问题文本对应的第二查询矩阵。
所述第一确定子模块,还可以用于根据所述所述上下文文本向量矩阵,分别确定所述问题文本对应的第二键矩阵和第二值矩阵。
所述计算子模块,可以用于根据所述第二查询矩阵、所述第二键矩阵和所述第二值矩阵,计算所述问题文本对应的第二文本向量矩阵。
在具体应用场景中,所述初始主题向量提取模型包括多个第二初始前馈神经网络,所述提取单元33,包括:确定模块331、相乘模块332、提取模块333和相加模块334。
所述确定模块331,可以用于确定所述多个第二初始前馈神经网络分别对应的主题向量参数。
所述相乘模块332,可以用于将所述第一文本向量矩阵和所述回复文本向量矩阵分别与所述多个主题向量参数相乘,得到所述第一文本向量矩阵对应的多个第一相乘结果和所述回复文本向量矩阵对应的多个第二相乘结果。
所述提取模块333,可以用于将所述多个第一相乘结果和所述多个第二相乘结果分别输入至相应的第二初始前馈神经网络中进行主题向量提取,得到提取的多个第一主题向量和多个第二主题向量。
所述相加模块334,可以用于将提取的所述多个第一主题向量相加,得到所述第一文本向量矩阵对应的上下文文本主题向量。
所述相加模块334,还可以用于将提取的所述多个第二主题向量相加,得到所述回复文本向量矩阵对应的回复文本主题向量。
在具体应用场景中,所述损失函数包括相似度损失函数和文本损失函数,所述构建单元34,包括:构建模块341和预测模块342。
所述构建模块341,可以用于分别计算多个所述上下文文本主题向量与所述回复文本主题向量之间的相似度,基于计算的多个相似度,构建所述相似度损失函数。
所述预测模块342,可以用于基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本。
所述构建模块341,还可以用于获取所述多轮对话对应的真实回复文本,基于所述真实回复文本和所述预测回复文本,构建所述文本损失函数。
进一步地,为了预测所述多轮对话对应的预测回复文本,所述预测模块342,包括:第二确定子模块、第二处理子模块、判定子模块、替换子模块和生成子模块。
所述第二确定子模块,可以用于从所述多个上下文文本中确定所述预测回复文本对应的关键词。
所述第二处理子模块,可以用于将所述回复文本向量矩阵输入至全连接层进行处理,并将经过处理后的回复文本向量矩阵输入至激活函数中进行处理,得到所述预测回复文本的各个位置索引对应的分词概率值。
所述判定子某块,可以用于基于所述分词概率值,确定所述各个位置索引处的回复分词,并判定各个分词概率值中是否存在大于预设概率值的目标分词概率值。
所述替换子模块,可以用于若存在所述目标分词概率值,则将所述目标分词概率值对应的位置索引处的回复分词替换成所述关键词。
所述生成子模块,可以用于根据所述关键词和其他位置索引处的回复分词,生成所述预测回复文本。
进一步地,所述第二确定子模块,具体可以用于确定所述多个上下文文本中的最长上下文文本;根据所述最长上下文文本对应的第一文本向量矩阵和其他上下文文本对应的第一文本向量矩阵,分别计算所述最长上下文文本与所述其他上下文文本之间的相似度矩阵;将计算的各个相似度矩阵进行横向拼接,并对拼接后的相似度矩阵按行求和,得到所述拼接后的相似度矩阵中各行对应的求和结果;从所述各行对应的求和结果中确定最大求和结果,并确定所述最大求和结果对应的行索引;将所述最长上下文文本中所述行索引处的分词确定为所述关键词。
需要说明的是,本申请实施例提供的一种文本生成模型的训练装置所涉及各功能模块的其他相应描述,可以参考图1所示方法的对应描述,在此不再赘述。
基于上述如图1所示方法,相应的,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质可以是非易失性,也可以是易失性,其上存储有计算机可读指令,该程序被处理器执行时实现以下步骤:获取多轮对话中的问题文本和多个上下文文本;利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
基于上述如图1所示方法和如图3所示装置的实施例,本申请实施例还提供了一种计算机设备的实体结构图,如图5所示,该计算机设备包括:处理器51、存储器52、及存储在存储器52上并可在处理器上运行的计算机可读指令,其中,存储器52和处理器51均设置在总线53上,所述处理器51执行所述程序时实现以下步骤:获取多轮对话中的问题文本和多个上下文文本;利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
通过本申请的技术方案,能够获取多轮对话中的问题文本和多个上下文文本;并利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;与此同时,利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;并基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;最终基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型,由此通过提取上下文主题向量和回复文本主题向量,并基于该上下文本主题向量和回复文本主题向量,构建损失函数对文本生成模型进行训练,能 够使回复文本主题向量和上下文主题向量尽可能相近,从而能够保证生成的回复文本与上下文对话主题深层次相关,使生成的回复文本贴合多轮对话的整体逻辑,进而提高了多轮对话中回复文本的生成精度。
显然,本领域的技术人员应该明白,上述的本申请的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本申请不限制于任何特定的硬件和软件结合。
以上所述仅为本申请的优选实施例而已,并不用于限制本申请,对于本领域的技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包括在本申请的保护范围之内。

Claims (20)

  1. 一种文本生成模型的训练方法,其中,包括:
    获取多轮对话中的问题文本和多个上下文文本;
    利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
    利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
    基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
    基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
  2. 根据权利要求1所述的方法,其中,所述初始文本向量生成模型包括初始编码器、初始解码器和第一初始前馈神经网络,所述利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵,包括:
    将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵;
    将多个所述第一文本向量矩阵进行拼接,得到所述多轮对话对应的上下文文本向量矩阵;
    将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至所述初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵;
    将所述第二文本向量矩阵输入至所述第一初始前馈神经网络中,得到所述问题文本对应的回复文本向量矩阵。
  3. 根据权利要求2所述的方法,其中,所述将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵,包括:
    对所述多个上下文文本分别对应的嵌入向量进行相应的线性变换,得到所述多个上下文文本分别对应的第一查询矩阵、第一键矩阵和第一值矩阵;
    对所述第一键矩阵进行转置处理,将转置后的第一键矩阵与所述第一查询矩阵相乘,得到所述多个上下文文本分别对应的注意力强度矩阵;
    将所述注意力强度矩阵输入至所述初始编码器中的softmax层进行归一化处理,得到所述多个上下文文本分别对应的注意力系数矩阵;
    将所述注意力系数矩阵与所述第一值矩阵相乘,得到所述多个上下文文本分别对应的第一文本向量矩阵;
    所述初始解码器包括第一注意力层和第二注意力层,所述将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵,包括:
    将所述问题文本对应的嵌入向量输入至所述第一注意力层进行文本特征提取,得到所述问题文本对应的第三文本向量矩阵;
    根据所述第三文本向量矩阵,确定所述问题文本对应的第二查询矩阵;
    根据所述所述上下文文本向量矩阵,分别确定所述问题文本对应的第二键矩阵和第二值矩阵;
    根据所述第二查询矩阵、所述第二键矩阵和所述第二值矩阵,计算所述问题文本对应的第二文本向量矩阵。
  4. 根据权利要求1所述的方法,其中,所述初始主题向量提取模型包括多个第二初始前馈神经网络,所述利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的 上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量,包括:
    确定所述多个第二初始前馈神经网络分别对应的主题向量参数;
    将所述第一文本向量矩阵和所述回复文本向量矩阵分别与所述多个主题向量参数相乘,得到所述第一文本向量矩阵对应的多个第一相乘结果和所述回复文本向量矩阵对应的多个第二相乘结果;
    将所述多个第一相乘结果和所述多个第二相乘结果分别输入至相应的第二初始前馈神经网络中进行主题向量提取,得到提取的多个第一主题向量和多个第二主题向量;
    将提取的所述多个第一主题向量相加,得到所述第一文本向量矩阵对应的上下文文本主题向量;
    将提取的所述多个第二主题向量相加,得到所述回复文本向量矩阵对应的回复文本主题向量。
  5. 根据权利要求1所述的方法,其中,所述损失函数包括相似度损失函数和文本损失函数,所述基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数,包括:
    分别计算多个所述上下文文本主题向量与所述回复文本主题向量之间的相似度,基于计算的多个相似度,构建所述相似度损失函数;
    基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本;
    获取所述多轮对话对应的真实回复文本,基于所述真实回复文本和所述预测回复文本,构建所述文本损失函数。
  6. 根据权利要求5所述的方法,其特征在于,所述基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本,包括:
    从所述多个上下文文本中确定所述预测回复文本对应的关键词;
    将所述回复文本向量矩阵输入至全连接层进行处理,并将经过处理后的回复文本向量矩阵输入至激活函数中进行处理,得到所述预测回复文本的各个位置索引对应的分词概率值:
    基于所述分词概率值,确定所述各个位置索引处的回复分词,并判定各个分词概率值中是否存在大于预设概率值的目标分词概率值;
    若存在所述目标分词概率值,则将所述目标分词概率值对应的位置索引处的回复分词替换成所述关键词;
    根据所述关键词和其他位置索引处的回复分词,生成所述预测回复文本。
  7. 根据权利要求6所述的方法,其特征在于,所述从所述多个上下文文本中确定所述预测回复文本对应的关键词,包括:
    确定所述多个上下文文本中的最长上下文文本;
    根据所述最长上下文文本对应的第一文本向量矩阵和其他上下文文本对应的第一文本向量矩阵,分别计算所述最长上下文文本与所述其他上下文文本之间的相似度矩阵;
    将计算的各个相似度矩阵进行横向拼接,并对拼接后的相似度矩阵按行求和,得到所述拼接后的相似度矩阵中各行对应的求和结果;
    从所述各行对应的求和结果中确定最大求和结果,并确定所述最大求和结果对应的行索引;
    将所述最长上下文文本中所述行索引处的分词确定为所述关键词。
  8. 一种文本生成模型的训练装置,其中,包括:
    获取单元,用于获取多轮对话中的问题文本和多个上下文文本;
    生成单元,用于利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
    提取单元,用于利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上 下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
    构建单元,用于基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
    训练单元,用于基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
  9. 一种计算机可读存储介质,其上存储有计算机可读指令,其中,所述计算机可读指令被处理器执行时实现文本生成模型的训练方法,包括:
    获取多轮对话中的问题文本和多个上下文文本;
    利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
    利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
    基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
    基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
  10. 根据权利要求9所述的计算机可读存储介质,其中,所述计算机可读指令被处理器执行时实现所述利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵,包括:
    将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵;
    将多个所述第一文本向量矩阵进行拼接,得到所述多轮对话对应的上下文文本向量矩阵;
    将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至所述初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵;
    将所述第二文本向量矩阵输入至所述第一初始前馈神经网络中,得到所述问题文本对应的回复文本向量矩阵。
  11. 根据权利要求10所述的计算机可读存储介质,其中,所述计算机可读指令被处理器执行时实现所述将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵,包括:
    对所述多个上下文文本分别对应的嵌入向量进行相应的线性变换,得到所述多个上下文文本分别对应的第一查询矩阵、第一键矩阵和第一值矩阵;
    对所述第一键矩阵进行转置处理,将转置后的第一键矩阵与所述第一查询矩阵相乘,得到所述多个上下文文本分别对应的注意力强度矩阵;
    将所述注意力强度矩阵输入至所述初始编码器中的softmax层进行归一化处理,得到所述多个上下文文本分别对应的注意力系数矩阵;
    将所述注意力系数矩阵与所述第一值矩阵相乘,得到所述多个上下文文本分别对应的第一文本向量矩阵;
    所述计算机可读指令被处理器执行时实现所述将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵,包括:
    将所述问题文本对应的嵌入向量输入至所述第一注意力层进行文本特征提取,得到所述问题文本对应的第三文本向量矩阵;
    根据所述第三文本向量矩阵,确定所述问题文本对应的第二查询矩阵;
    根据所述所述上下文文本向量矩阵,分别确定所述问题文本对应的第二键矩阵和第二值矩阵;
    根据所述第二查询矩阵、所述第二键矩阵和所述第二值矩阵,计算所述问题文本对应的第二文本向量矩阵。
  12. 根据权利要求9所述的计算机可读存储介质,其中,所述计算机可读指令被处理器执行时实现所述利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量,包括:
    确定所述多个第二初始前馈神经网络分别对应的主题向量参数;
    将所述第一文本向量矩阵和所述回复文本向量矩阵分别与所述多个主题向量参数相乘,得到所述第一文本向量矩阵对应的多个第一相乘结果和所述回复文本向量矩阵对应的多个第二相乘结果;
    将所述多个第一相乘结果和所述多个第二相乘结果分别输入至相应的第二初始前馈神经网络中进行主题向量提取,得到提取的多个第一主题向量和多个第二主题向量;
    将提取的所述多个第一主题向量相加,得到所述第一文本向量矩阵对应的上下文文本主题向量;
    将提取的所述多个第二主题向量相加,得到所述回复文本向量矩阵对应的回复文本主题向量。
  13. 根据权利要求9所述的计算机可读存储介质,其中,所述计算机可读指令被处理器执行时实现所述损失函数包括相似度损失函数和文本损失函数,所述基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数,包括:
    分别计算多个所述上下文文本主题向量与所述回复文本主题向量之间的相似度,基于计算的多个相似度,构建所述相似度损失函数;
    基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本;
    获取所述多轮对话对应的真实回复文本,基于所述真实回复文本和所述预测回复文本,构建所述文本损失函数。
  14. 根据权利要求13所述的计算机可读存储介质,其中,所述基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本,包括:
    从所述多个上下文文本中确定所述预测回复文本对应的关键词;
    将所述回复文本向量矩阵输入至全连接层进行处理,并将经过处理后的回复文本向量矩阵输入至激活函数中进行处理,得到所述预测回复文本的各个位置索引对应的分词概率值:
    基于所述分词概率值,确定所述各个位置索引处的回复分词,并判定各个分词概率值中是否存在大于预设概率值的目标分词概率值;
    若存在所述目标分词概率值,则将所述目标分词概率值对应的位置索引处的回复分词替换成所述关键词;
    根据所述关键词和其他位置索引处的回复分词,生成所述预测回复文本。
  15. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机可读指令,其中,所述计算机可读指令被处理器执行时实现文本生成模型的训练方法,包括:
    获取多轮对话中的问题文本和多个上下文文本;
    利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵;
    利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量;
    基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数;
    基于所述损失函数共同对所述初始文本向量生成模型和所述初始主题向量提取模型进行迭代训练,构建文本生成模型。
  16. 根据权利要求15所述的计算机设备,其中,所述计算机可读指令被处理器执行时实现所述利用初始文本向量生成模型生成所述多个上下文文本分别对应的第一文本向量矩阵和所述问题文本对应的回复文本向量矩阵,包括:
    将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵;
    将多个所述第一文本向量矩阵进行拼接,得到所述多轮对话对应的上下文文本向量矩阵;
    将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至所述初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵;
    将所述第二文本向量矩阵输入至所述第一初始前馈神经网络中,得到所述问题文本对应的回复文本向量矩阵。
  17. 根据权利要求16所述的计算机设备,其中,所述计算机可读指令被处理器执行时实现所述将所述多个上下文文本分别对应的嵌入向量矩阵输入至所述初始编码器中进行编码,得到所述多个上下文文本分别对应的第一文本向量矩阵,包括:
    对所述多个上下文文本分别对应的嵌入向量进行相应的线性变换,得到所述多个上下文文本分别对应的第一查询矩阵、第一键矩阵和第一值矩阵;
    对所述第一键矩阵进行转置处理,将转置后的第一键矩阵与所述第一查询矩阵相乘,得到所述多个上下文文本分别对应的注意力强度矩阵;
    将所述注意力强度矩阵输入至所述初始编码器中的softmax层进行归一化处理,得到所述多个上下文文本分别对应的注意力系数矩阵;
    将所述注意力系数矩阵与所述第一值矩阵相乘,得到所述多个上下文文本分别对应的第一文本向量矩阵;
    所述计算机可读指令被处理器执行时实现所述将所述上下文文本向量矩阵和所述问题文本对应的嵌入向量一同输入至初始解码器中进行解码,得到所述问题文本对应的第二文本向量矩阵,包括:
    将所述问题文本对应的嵌入向量输入至所述第一注意力层进行文本特征提取,得到所述问题文本对应的第三文本向量矩阵;
    根据所述第三文本向量矩阵,确定所述问题文本对应的第二查询矩阵;
    根据所述所述上下文文本向量矩阵,分别确定所述问题文本对应的第二键矩阵和第二值矩阵;
    根据所述第二查询矩阵、所述第二键矩阵和所述第二值矩阵,计算所述问题文本对应的第二文本向量矩阵。
  18. 根据权利要求15所述的计算机设备,其中,所述计算机可读指令被处理器执行时实现所述利用初始主题向量提取模型分别提取所述第一文本向量矩阵对应的上下文文本主题向量和所述回复文本向量矩阵对应的回复文本主题向量,包括:
    确定所述多个第二初始前馈神经网络分别对应的主题向量参数;
    将所述第一文本向量矩阵和所述回复文本向量矩阵分别与所述多个主题向量参数相乘,得到所述第一文本向量矩阵对应的多个第一相乘结果和所述回复文本向量矩阵对应的多个第二相乘结果;
    将所述多个第一相乘结果和所述多个第二相乘结果分别输入至相应的第二初始前馈神经网络中进行主题向量提取,得到提取的多个第一主题向量和多个第二主题向量;
    将提取的所述多个第一主题向量相加,得到所述第一文本向量矩阵对应的上下文文本主题向量;
    将提取的所述多个第二主题向量相加,得到所述回复文本向量矩阵对应的回复文本主题向量。
  19. 根据权利要求15所述的计算机设备,其中,所述计算机可读指令被处理器执行时实现所述损失函数包括相似度损失函数和文本损失函数,所述基于所述上下文文本主题向量和所述回复文本主题向量,构建损失函数,包括:
    分别计算多个所述上下文文本主题向量与所述回复文本主题向量之间的相似度,基于计算的多个相似度,构建所述相似度损失函数;
    基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本;
    获取所述多轮对话对应的真实回复文本,基于所述真实回复文本和所述预测回复文本,构建所述文本损失函数。
  20. 根据权利要求19所述的计算机设备,其中,所述基于所述回复文本向量矩阵,预测所述多轮对话对应的预测回复文本,包括:
    从所述多个上下文文本中确定所述预测回复文本对应的关键词;
    将所述回复文本向量矩阵输入至全连接层进行处理,并将经过处理后的回复文本向量矩阵输入至激活函数中进行处理,得到所述预测回复文本的各个位置索引对应的分词概率值:
    基于所述分词概率值,确定所述各个位置索引处的回复分词,并判定各个分词概率值中是否存在大于预设概率值的目标分词概率值;
    若存在所述目标分词概率值,则将所述目标分词概率值对应的位置索引处的回复分词替换成所述关键词;
    根据所述关键词和其他位置索引处的回复分词,生成所述预测回复文本。
PCT/CN2022/089734 2021-12-15 2022-04-28 文本生成模型的训练方法、装置、存储介质及计算机设备 WO2023108981A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111534333.9A CN114238549A (zh) 2021-12-15 2021-12-15 文本生成模型的训练方法、装置、存储介质及计算机设备
CN202111534333.9 2021-12-15

Publications (1)

Publication Number Publication Date
WO2023108981A1 true WO2023108981A1 (zh) 2023-06-22

Family

ID=80756351

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/089734 WO2023108981A1 (zh) 2021-12-15 2022-04-28 文本生成模型的训练方法、装置、存储介质及计算机设备

Country Status (2)

Country Link
CN (1) CN114238549A (zh)
WO (1) WO2023108981A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114238549A (zh) * 2021-12-15 2022-03-25 平安科技(深圳)有限公司 文本生成模型的训练方法、装置、存储介质及计算机设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107632987A (zh) * 2016-07-19 2018-01-26 腾讯科技(深圳)有限公司 一种对话生成方法及装置
US20180329884A1 (en) * 2017-05-12 2018-11-15 Rsvp Technologies Inc. Neural contextual conversation learning
CN113094475A (zh) * 2021-06-08 2021-07-09 成都晓多科技有限公司 一种基于上下文注意流的对话意图识别系统及方法
CN113591462A (zh) * 2021-07-28 2021-11-02 咪咕数字传媒有限公司 弹幕回复生成方法、装置及电子设备
CN114238549A (zh) * 2021-12-15 2022-03-25 平安科技(深圳)有限公司 文本生成模型的训练方法、装置、存储介质及计算机设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107632987A (zh) * 2016-07-19 2018-01-26 腾讯科技(深圳)有限公司 一种对话生成方法及装置
US20180329884A1 (en) * 2017-05-12 2018-11-15 Rsvp Technologies Inc. Neural contextual conversation learning
CN113094475A (zh) * 2021-06-08 2021-07-09 成都晓多科技有限公司 一种基于上下文注意流的对话意图识别系统及方法
CN113591462A (zh) * 2021-07-28 2021-11-02 咪咕数字传媒有限公司 弹幕回复生成方法、装置及电子设备
CN114238549A (zh) * 2021-12-15 2022-03-25 平安科技(深圳)有限公司 文本生成模型的训练方法、装置、存储介质及计算机设备

Also Published As

Publication number Publication date
CN114238549A (zh) 2022-03-25

Similar Documents

Publication Publication Date Title
Bahdanau et al. Learning to compute word embeddings on the fly
CN112528672B (zh) 一种基于图卷积神经网络的方面级情感分析方法及装置
CN108052512B (zh) 一种基于深度注意力机制的图像描述生成方法
US11544474B2 (en) Generation of text from structured data
Zhang et al. Deep Neural Networks in Machine Translation: An Overview.
CN106502985B (zh) 一种用于生成标题的神经网络建模方法及装置
CN109661664B (zh) 一种信息处理的方法及相关装置
CN111814466A (zh) 基于机器阅读理解的信息抽取方法、及其相关设备
CN107273913B (zh) 一种基于多特征融合的短文本相似度计算方法
CN109740158B (zh) 一种文本语义解析方法及装置
CN110765785A (zh) 基于神经网络的中英翻译方法、及其相关设备
Khan et al. RNN-LSTM-GRU based language transformation
CN111401081A (zh) 神经网络机器翻译方法、模型及模型形成方法
Jian et al. [Retracted] LSTM‐Based Attentional Embedding for English Machine Translation
WO2023108981A1 (zh) 文本生成模型的训练方法、装置、存储介质及计算机设备
CN111507108B (zh) 别名生成方法、装置、电子设备及计算机可读存储介质
CN111126056B (zh) 一种识别触发词的方法及装置
CN110321568B (zh) 基于融合词性和位置信息的汉-越卷积神经机器翻译方法
CN112464655A (zh) 中文字符和拼音相结合的词向量表示方法、装置、介质
CN116955644A (zh) 基于知识图谱的知识融合方法、系统及存储介质
CN115203388A (zh) 机器阅读理解方法、装置、计算机设备和存储介质
CN115310445A (zh) 基于增强序列标注策略的单阶段联合实体关系抽取方法及系统
Zhang et al. Byte-level recursive convolutional auto-encoder for text
CN112926334A (zh) 确定词表示向量的方法、装置及电子设备
Nguyen et al. Information extraction of domain-specific business documents with limited data

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22905749

Country of ref document: EP

Kind code of ref document: A1