CN113392193A - Dialog text generation method and device - Google Patents

Dialog text generation method and device Download PDF

Info

Publication number
CN113392193A
CN113392193A CN202010179197.5A CN202010179197A CN113392193A CN 113392193 A CN113392193 A CN 113392193A CN 202010179197 A CN202010179197 A CN 202010179197A CN 113392193 A CN113392193 A CN 113392193A
Authority
CN
China
Prior art keywords
text
artificial intelligence
intelligence model
decoding
dialog
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Withdrawn
Application number
CN202010179197.5A
Other languages
Chinese (zh)
Inventor
叶凯亮
胡盼盼
赵茜
胡浩
佟博
高玮
周玥
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Bozhilin Robot Co Ltd
Original Assignee
Guangdong Bozhilin Robot Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Bozhilin Robot Co Ltd filed Critical Guangdong Bozhilin Robot Co Ltd
Priority to CN202010179197.5A priority Critical patent/CN113392193A/en
Publication of CN113392193A publication Critical patent/CN113392193A/en
Withdrawn legal-status Critical Current

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/33Querying
    • G06F16/332Query formulation
    • G06F16/3329Natural language query formulation or dialogue systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/35Clustering; Classification

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Human Computer Interaction (AREA)
  • Computational Linguistics (AREA)
  • Machine Translation (AREA)

Abstract

The embodiment of the application provides a dialog text generation method and a dialog text generation device, which relate to the technical field of natural language processing, and the method comprises the following steps: receiving input alternating text; coding the alternating current text according to a preset artificial intelligence model to obtain a coded text; decoding the coded text according to the artificial intelligence model to obtain a decoded text; and classifying the decoded text according to a classifier included in the artificial intelligence model to obtain the dialog text. Therefore, by implementing the implementation mode, the dialog text can be generated, so that the intelligent dialog problem of intelligent software or an intelligent robot is solved, and the intelligence of the current intelligent software or the intelligent robot is improved.

Description

Dialog text generation method and device
Technical Field
The present application relates to the field of natural language processing technologies, and in particular, to a dialog text generation method and apparatus.
Background
With the continuous progress of science and technology, more and more intelligent software appears in the visual field of people, and the intelligent software brings great convenience to people by unique interaction capacity and processing capacity. However, in practice, it is found that the current intelligent software generally only uses a database for character recognition and dialogue, and therefore does not have corresponding intelligent dialogue capability, so that how to enable intelligent software or an intelligent robot to intelligently dialogue becomes one of the problems that all technicians want to solve.
Disclosure of Invention
An object of the embodiments of the present application is to provide a method and an apparatus for generating a dialog text, which can generate a dialog text, thereby being beneficial to solving an intelligent dialog problem of intelligent software or an intelligent robot, and increasing the intelligence of the current intelligent software or the intelligent robot.
A first aspect of an embodiment of the present application provides a dialog text generation method, where the method includes:
receiving input alternating text;
coding the alternating current text according to a preset artificial intelligence model to obtain a coded text;
decoding the coded text according to the artificial intelligence model to obtain a decoded text;
and classifying the decoded text according to a classifier included in the artificial intelligence model to obtain a dialog text.
In the implementation process, the method can preferentially receive the communication text input by the user, wherein the communication text can be a question text or other texts for communication; on the basis of obtaining the alternating text, the method encodes the alternating text according to a preset artificial intelligence model to obtain an encoded text, wherein the encoded text has numerous information characteristics; meanwhile, after acquiring the coded text characters, the method decodes the coded text through a decoder included in the artificial intelligence model so that a plurality of characteristics included in the coded text can be analyzed one by one to obtain a decoded text, wherein the decoded text has a plurality of reply text characteristics; finally, the method can classify the decoded text according to a classifier included in the artificial intelligence model, so that the plurality of reply text features can obtain corresponding probability information through the classifier, and the artificial intelligence model can determine the final dialog text according to the probability information. Therefore, by implementing the implementation mode, the response process of the communication text can be completed through the artificial intelligence model after the communication text is received, wherein the artificial intelligence model comprises an encoder, a decoder and a classifier, and can realize the deep recognition, the response characteristic generation and the generation of the conversation text of the communication text, so that the accurate generation of the conversation text can be realized, the intelligent conversation problem of intelligent software or an intelligent robot can be solved, and the intelligence of the intelligent software or the intelligent robot at present is increased.
Further, the step of encoding the alternating-current text according to a preset artificial intelligence model to obtain an encoded text includes:
performing word vector conversion on the alternating text according to a word embedding algorithm included in a preset artificial intelligence model to obtain an alternating word vector;
carrying out position coding on the alternating word vector to obtain a first position coding vector;
and coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coded text.
In the implementation process, when the method is used for coding the alternating-current text, the method can firstly perform word vector conversion on the alternating-current text according to a word embedding algorithm included in a preset artificial intelligence model to obtain an alternating-current word vector, and generally, each word is embedded into a 512-dimensional vector; after the alternating word vectors are obtained, the method carries out position coding on the alternating word vectors, and therefore the added position coding vectors can enable an artificial intelligence model to understand the sequence among words, so that the values of the vectors follow a specific mode; after the position coding is carried out by the method, the first position coding vector is coded again according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coded text, so that the coded text can be finally obtained. Therefore, by implementing the implementation mode, word vector conversion, position coding and coding based on a multi-head attention mechanism can be successively carried out when the alternating text is coded in the artificial intelligence model, so that the coded text has a large number of characteristic parameters, and can be decoded in a targeted manner according to the large number of characteristic parameters, and the accuracy of generating the dialog text is improved.
Further, the step of encoding the first position encoding vector according to a multi-head attention mechanism included in the artificial intelligence model to obtain an encoded text includes:
coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coding process text;
and inputting the coding process text into a transition function included in the artificial intelligence model to perform circular operation to obtain a coding text.
In the implementation process, in the process of coding the first position coding vector according to the multi-head attention mechanism to obtain the coded text, the method can preferentially code the first position coding vector according to the multi-head attention mechanism included in the artificial intelligence model to obtain the coded text; after the encoding process text is obtained, the encoding process text is input into a transition function included in the artificial intelligent model to carry out circular operation, so that the method can continuously carry out operation in self-adaptive computing time, and finally, an accurate and effective encoding text is obtained. Therefore, by implementing the implementation mode, the method can perform circular operation through a transition function sharing weight, so that the accuracy of the finally output coded text is higher, the use effect is better, the decoding process is facilitated, and the generation accuracy of the dialog text can be further improved.
Further, the step of decoding the encoded text according to the artificial intelligence model to obtain a decoded text includes:
decoding the coded text according to a multi-head attention mechanism included by the artificial intelligence model and a sequence mask algorithm included by the artificial intelligence model to obtain a decoded pre-text;
decoding the decoding preposed text according to a multi-head attention mechanism included by the artificial intelligence model to obtain a decoding process text;
and inputting the decoding process text into a transition function included in the artificial intelligence model to perform circular operation to obtain a decoding text.
In the implementation process, in the decoding process, the method can preferentially decode the encoded text according to a multi-head attention mechanism included by the artificial intelligence model and a sequence mask algorithm included by the artificial intelligence model to obtain a decoded pre-text, wherein the decoded pre-text is obtained by mask decoding, and therefore the method decodes the decoded pre-text according to the multi-head attention mechanism included by the artificial intelligence model to obtain a decoding process text; therefore, in the decoding process, the method can improve the pertinence of decoding, thereby improving the accuracy of the decoding process; after the decoding process text is obtained, the method can also input the decoding process text into a transition function included in the artificial intelligent model to carry out circular operation to obtain the decoding text, so that the decoding process corresponds to the encoding process, and the characteristic parameters required by the dialog text can be obtained. Therefore, by implementing the implementation mode, the method can finish primary decoding of the coded text by using the mask multi-head attention mechanism layer in the decoding process, and carry out secondary decoding through the multi-head attention layer, so that the text in the decoding process after secondary decoding can be circularly operated to obtain the decoded text, thereby improving the pertinence of the decoded text and the accuracy of the obtained characteristic parameters, and further improving the generation accuracy of the final dialog text.
Further, the step of classifying the decoded text according to the classifier included in the artificial intelligence model to obtain a dialog text includes:
classifying the decoded text according to a classifier included in the artificial intelligence model to obtain text vector probability;
and generating a text according to the decoded word vector and the text vector probability included by the artificial intelligence model to obtain a dialog text.
In the implementation process, in the process of classifying the decoded text to obtain the dialog text, the method can preferentially classify the decoded text according to the classifier to obtain the text vector probability, wherein the text vector can correspond to the characteristic parameters; and then generating a text according to the decoded word vector and the text vector probability included by the artificial intelligence model to obtain the dialog text. Therefore, by implementing the embodiment, the corresponding preparation vocabulary (namely the text vector) can be generated according to the large number of embedded text vectors and the final dialog text can be determined according to the position, the accuracy probability and other characteristics of the text vector after the text vector is acquired, so that the generation of the dialog text can be realized.
A second aspect of the embodiments of the present application provides a dialog text generation apparatus, including:
the receiving unit is used for receiving the input alternating text;
the encoding unit is used for encoding the alternating-current text according to a preset artificial intelligence model to obtain an encoded text;
the decoding unit is used for decoding the coded text according to the artificial intelligence model to obtain a decoded text;
and the generating unit is used for classifying the decoded text according to the classifier included by the artificial intelligence model to obtain the dialog text.
In the implementation process, the dialog text generation device may receive the input interchange text through the receiving unit; then, coding the alternating current text according to a preset artificial intelligence model through a coding unit to obtain a coded text; then, decoding the coded text according to the artificial intelligence model through a decoding unit to obtain a decoded text; and finally, classifying the decoded text according to a classifier included in the artificial intelligence model through a generating unit to obtain the dialog text. Therefore, by implementing the implementation mode, targeted and efficient work can be realized through the cooperative cooperation among the multiple units, and the work division and cooperation capability of the text generation device is facilitated; meanwhile, the dialog text generation device can divide the artificial intelligence model into a plurality of units, and the effect improvement of respective functions is realized; in addition, the dialog text generation device can complete the reply process of the communication text through an artificial intelligence model after receiving the communication text; the artificial intelligence model comprises an encoder, a decoder and a classifier, and can realize the deep recognition of the communication text, the generation of the response characteristics and the generation of the conversation text, so that the accurate generation of the conversation text can be realized, the intelligent conversation problem of intelligent software or an intelligent robot can be solved, and the intelligence of the current intelligent software or the intelligent robot is improved.
Further, the encoding unit includes:
the conversion subunit is used for carrying out word vector conversion on the alternating text according to a word embedding algorithm included by a preset artificial intelligence model to obtain an alternating word vector;
the first coding subunit is used for carrying out position coding on the alternating word vector to obtain a first position coding vector;
and the second coding subunit is used for coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coded text.
In the implementation process, the coding unit can perform word vector conversion on the alternating-current text according to a word embedding algorithm included in a preset artificial intelligence model through the conversion subunit to obtain an alternating-current word vector; carrying out position coding on the alternating word vector through a first coding subunit to obtain a first position coding vector; and then, the second coding subunit codes the first position coding vector according to a multi-head attention mechanism included in the artificial intelligence model to obtain a coded text. Therefore, by implementing the implementation mode, word vector conversion, position coding and coding based on a multi-head attention mechanism can be successively carried out when the alternating text is coded in the artificial intelligence model, so that the coded text has a large number of characteristic parameters, and can be conveniently and subsequently decoded in a targeted manner according to the large number of characteristic parameters, thereby improving the accuracy of generating the dialog text.
Further, the decoding unit includes:
the first decoding subunit is configured to decode the encoded text according to a multi-head attention mechanism included in the artificial intelligence model and a sequence mask algorithm included in the artificial intelligence model, so as to obtain a decoded pre-text;
the second decoding subunit is configured to decode the decoding pre-text according to a multi-head attention mechanism included in the artificial intelligence model, so as to obtain a decoding process text;
and the decoding circulation subunit is used for inputting the decoding process text into the transition function included in the artificial intelligence model to perform circulation operation, so as to obtain a decoding text.
In the implementation process, the decoding unit may decode the encoded text according to a multi-head attention mechanism included in the artificial intelligence model and a sequence mask algorithm included in the artificial intelligence model through the first decoding subunit to obtain a decoded pre-text; decoding the decoding pre-text according to a multi-head attention mechanism included by the artificial intelligence model through a second decoding subunit to obtain a decoding process text; and inputting the decoding process text into a transition function included in the artificial intelligent model through a decoding circulation subunit to perform circulation operation, so as to obtain a decoding text. Therefore, by implementing the implementation mode, the primary decoding of the coded text can be completed by using the mask multi-head attention mechanism layer in the decoding process, and the secondary decoding is performed through the multi-head attention layer, so that the text in the decoding process after the secondary decoding can be circularly operated to obtain the decoded text, the pertinence of the decoded text and the accuracy of the obtained characteristic parameters are improved, and the generation accuracy of the final dialog text can be improved.
A third aspect of the embodiments of the present application provides an electronic device, including a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the dialog text generation method according to any one of the first aspect of the embodiments of the present application.
A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores computer program instructions, and when the computer program instructions are read and executed by a processor, the computer program instructions perform the dialog text generation method according to any one of the first aspect of the embodiments of the present application.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a schematic flowchart of a dialog text generation method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of another dialog text generation method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a dialog text generation apparatus according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of another dialog text generation apparatus according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a network for an attention mechanism in an artificial intelligence model according to an embodiment of the present disclosure;
FIG. 6 is a schematic diagram illustrating a loop operation process of the artificial intelligence model according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of an artificial intelligence model according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Example 1
Referring to fig. 1, fig. 1 is a schematic flow chart of a dialog text generation method according to an embodiment of the present application. The method can be applied to various intelligent dialogue scenes, particularly, the method can be applied to an artificial intelligent dialogue robot and intelligent dialogue software. The dialog text generation method comprises the following steps:
s101, receiving an input alternating text.
In this embodiment, the text to be exchanged is a text sequence input by the user.
In this embodiment, the communication text may be in germany languages such as chinese, english, russian, french, and the like, and this embodiment is not limited at all.
In this embodiment, the receiving mode of the text communication may be voice receiving, and may be text input, which is not limited in this embodiment.
In this embodiment, the communication text refers to a text for communication, where the communication text may be a question and may be a daily conversation content; for example, the communication text may be "how to log on to the system? Or is "how do the vegetables get good? "and the like.
S102, coding the alternating current text according to a preset artificial intelligence model to obtain a coded text.
In this embodiment, the method is a process in which the artificial intelligence model processes the communicated text, and in the process, the artificial intelligence model wants to unify the communicated text first, so that the communicated text can be processed in a unified processing manner; after the unification treatment, because the text has the language order characteristics, the position code is added, so that the communication text has the mark of the position characteristics, and the communication text can be conveniently understood according to the position characteristics; after the position coding, the artificial intelligence model also needs to perform multi-head attention coding on the alternating-current text, so that the alternating-current text can generate a corresponding targeted coded text according to an attention mechanism.
In this embodiment, the process of the encoding is unified into the embedding of the input text, and the process can make the dimensions of the input text the same, which is beneficial to artificial intelligence processing.
In this embodiment, the position code may be code information added to the fixed-dimension alternating text (i.e., alternating word vector), and the combination of the code information and the alternating word vector constitutes the complete first position code vector.
In this embodiment, the artificial intelligence model encodes the first position-encoding vector according to a multi-head attention mechanism to obtain an encoded text.
In this embodiment, the encoded text may be understood as an interchange text understood by the artificial intelligence model; encoded text may also be understood as process response text that the artificial intelligence model makes to the communicated text itself.
In this embodiment, the artificial intelligence model may understand the communication text in the encoding process, and then reply to the understood communication text in the decoding process; the artificial intelligence model may also understand the communication text first in the encoding process, and perform a preliminary response according to the understood communication text, so that the decoding process may decode the preliminary response text to obtain a final dialog text element, which is not described in detail in this embodiment.
S103, decoding the coded text according to the artificial intelligence model to obtain a decoded text.
In this embodiment, the decoding process may be a reply process to the encoded text, or may be a translation process to the encoded text (here, the encoded text is a reply result because the encoding process performs a preliminary reply), which is not limited in this embodiment.
In this embodiment, the decoded text is a large number of feature sets that constitute the dialog text, and the corresponding dialog text is obtained only after the classifier classifies the feature sets.
And S104, classifying the decoded text according to a classifier included in the artificial intelligence model to obtain a conversation text.
In this embodiment, the classifier is an artificial intelligence model including a softmax classifier.
In this embodiment, the classifier not only classifies the text feature vectors, but also classifies the position-coding information, so that the final dialog text has higher accuracy.
In this embodiment, the artificial intelligence model used in the method may refer to a transform model (a translation model), which is not described in this embodiment again.
In the present embodiment, the Transformer model is an artificial intelligence model based on a self-attention mechanism (an attention mechanism simulates an internal process of biological observation behavior, that is, a mechanism of aligning internal experience with external feeling to increase the observation fineness of a partial region). The Transformer model is an autoregressive model that makes predictions only once and uses the results of previous predictions to determine what needs to be done next.
In this embodiment, during the training of the artificial intelligence model, the artificial intelligence model will force the true output to be passed to the next time step, regardless of what the artificial intelligence model predicted at the current time step. For example, when the artificial intelligence model predicts each word, the self-attention mechanism allows it to look at the previous word in the input sequence (the alternating text) to better predict the next word. Meanwhile, in order to prevent the artificial intelligence model from reaching the expected peak value when being output, the artificial intelligence model uses a prospective mask (mask decoding operation in the decoding process) so that the coded text is divided into the input of the decoder and the clipped result, wherein the clipped result can be used for calculating the loss and the precision of the artificial intelligence model.
In this embodiment, the main body of the dialog text generation method may be a computing device such as a computer or a server, and the present embodiment is not limited at all.
In this embodiment, an execution subject of the dialog text generation method may also be an intelligent device such as a smart phone and a tablet, which is not limited in this embodiment.
In this embodiment, in the using process of the dialog text generation method, the artificial intelligence model (i.e., the Universal Transformer question-and-answer dialog generation model) may be trained through a large amount of question-and-dialog training data, so that the artificial intelligence model may receive the input question text and generate the reply text in the using process.
In this embodiment, a specific dialog generation example is shown as follows: the artificial intelligence model may receive a "Q: how to log on to the system? A: a system login guide. "so that the artificial intelligence model can receive the communication text of" login system "in the using process, so that the artificial intelligence can generate the conversation text of" system login guide ".
It can be seen that, by implementing the dialog text generation method described in fig. 1, the communication text input by the user can be preferentially received, where the communication text may be a question text, and may also be other texts used for communication; on the basis of obtaining the alternating text, the method encodes the alternating text according to a preset artificial intelligence model to obtain an encoded text, wherein the encoded text has numerous information characteristics; meanwhile, after acquiring the coded text characters, the method decodes the coded text through a decoder included in the artificial intelligence model so that a plurality of characteristics included in the coded text can be analyzed one by one to obtain a decoded text, wherein the decoded text has a plurality of reply text characteristics; finally, the method can classify the decoded text according to a classifier included in the artificial intelligence model, so that the plurality of reply text features can obtain corresponding probability information through the classifier, and the artificial intelligence model can determine the final dialog text according to the probability information. Therefore, by implementing the implementation mode, the response process of the communication text can be completed through the artificial intelligence model after the communication text is received, wherein the artificial intelligence model comprises an encoder, a decoder and a classifier, and can realize the deep recognition, the response characteristic generation and the generation of the conversation text of the communication text, so that the accurate generation of the conversation text can be realized, the intelligent conversation problem of intelligent software or an intelligent robot can be solved, and the intelligence of the intelligent software or the intelligent robot at present is increased.
Example 2
Referring to fig. 2, fig. 2 is a schematic flowchart of another dialog text generation method according to an embodiment of the present application. The flow diagram of the dialog text generation method depicted in fig. 2 is improved from the flow diagram of the dialog text generation method depicted in fig. 1. The dialog text generation method comprises the following steps:
s201, receiving an input alternating text.
In this embodiment, the communication text may be understood as a communication text such as a question input by the user.
S202, performing word vector conversion on the alternating-current text according to a word embedding algorithm included in a preset artificial intelligence model to obtain an alternating-current word vector.
In this embodiment, the process, like most NLP applications, preferentially converts each input word into a word vector through a word embedding algorithm.
In this embodiment, each word included in the above-mentioned AC text can be embedded into a 512-dimensional vector, and the word embedding process only occurs in the bottom-most encoder.
In this embodiment, there are many encoders, but all encoders have a similar feature in that they receive a vector list, each vector in the vector list having a size of 512 dimensions. In this process, this 512-dimensional vector is the word vector for the word, and in other encoders it is the output of the next encoder (also a vector list). The size of the vector list is a super parameter that we can set, and the super parameter is generally the length of the longest sentence in our training set.
S203, carrying out position coding on the alternating word vector to obtain a first position coding vector.
In this embodiment, the first position encoding vector is a feature vector having a position feature, a sense feature, and the like. Wherein, the position feature is used to refer to the absolute position and the relative position of the alternating word vector in the sentence.
In this embodiment, a position code is added to provide the artificial intelligence model with information about the relative position of the word in the sentence. Wherein the position-coding vector is added to the alternating-current-word vector (i.e., Embedding vector) so that vectors having similar meanings in the sentence are closer to each other. However, this process does not encode the relative positions of words in a sentence, resulting in sequence information that cannot be captured. Therefore, in this embodiment, the relative information or absolute information of the word segmentation of the sequence is used, and after the position code is added, the meaning of the word and the similarity of the word in the sentence in the d-dimensional space are close to each other. Wherein the position information is calculated by the formula PE(pos,2i)=sin(pos/10000^(2i/dmodel) ) and PE(pos,2i+1)=cos(pos/10000^(2i/dmodel) Pos represents the word and i represents the dimension embedded in the vector (embedding).
In this embodiment, the process of position coding may be the addition of position coding to the alternating word vector. The process can be understood as adding a part of codes with position information on the original alternating word vector, thereby completing the whole position coding and obtaining the final first position coding vector.
And S204, coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coding process text.
In this embodiment, the multi-head attention mechanism can expand the ability of the model to focus on different positions, and the disease can give a plurality of "representation subspaces" of the attention layer.
In this embodiment, for the application process and the calculation process of the multi-head attention mechanism, no corresponding known description is made in this embodiment.
In this embodiment, the artificial intelligence model uses a scaled dot product attention mechanism, which requires three inputs, Q (query vector), K (key vector), and V (value vector). Where this process can be understood as generating three vectors from the input vectors of each encoder (word vectors for each word) in the first step of the calculation of self-attention, i.e. for each word we create a query vector, a key vector and a value vector. These three vectors are created by post-multiplication of the word embedding with three weight matrices (preset).
In the present embodiment, these new vectors are lower in dimension than the above-described ac word vectors because the dimension of these new vectors is 64, and the dimension of the ac word vectors is 512. However, in practice, a smaller dimension is not mandatory, but is an architectural based choice that keeps most of the calculations of multi-head attention unchanged.
In this embodiment, the new vector such as Q, K, V is obtained by calculating the alternating-current word vector and the corresponding weight matrix.
In the present embodiment, self-Attention can be given by the formula Attention (Q, K, V) ═ softmax _ K ((QK ^ T)/√ (d)k) V) is calculated. Where the aforementioned Attention (Q, K, V) is a weight vector expressed as a self-Attention weight (weight is a product of a value vector and a representation of the word (key vector) by a dot product of the representation of the word (key vector) and a representation of the word to be encoded (query vector) by softmax). It can be seen that this self-attention calculation method can ensure that the words it is interested in remain intact, while irrelevant or non-interested words are removed. Wherein the attention of dot product is given by √ (d)k) It was decided to do so because for larger onesDepth value dkQK ^ T is also large, and the softmax function can be pushed into a region with extremely small gradient, so that the instability of the gradient is avoided.
In this embodiment, fig. 5 provides a network diagram of an attention mechanism in an artificial intelligence model, which is fully explained above.
In this embodiment, the encoder included in the artificial intelligence model is composed of an embedded layer, a position coding layer, a multi-head attention coding layer, and 2 fully-connected layers (sense layers).
And S205, inputting the text in the coding process into a transition function included in the artificial intelligent model to perform circular operation to obtain a coded text.
In this embodiment, the artificial intelligence model can input data into the Transition layer (Transition layer), and then perform a loop operation through a Transition function (Transition function) sharing a weight.
Referring to fig. 6, fig. 6 is a schematic diagram illustrating a loop operation process of the artificial intelligence model. In fig. 6, each position state refers to the position of each input h in a sequence, and the horizontal time refers to the sequence mainly in calculation. A text sequence is input, is firstly represented as h through embedded coding, and is represented as h +1 through an attention layer and a transition layer. Wherein, A ^ t ^ LayerNorm (H ^ t-1) + MultiHeadAttention (H ^ t-1) -P ^ t)) and H ^ t ^ LayerNorm (A ^ t + Transition (A ^ t)).
In this embodiment, the transform position surface only needs to consider the position of the text, and there is a time dimension more, so Coordinate embedding (Coordinate embedding) is performed again every cycle. Each coordinate embedding can be performed by the formulas P _ (pos,2j) ^ t ^ sin (pos/& lt 10000 ^ (2j/d)) & gt sin (t/& lt 10000 ^ (2j/d)) and P _ (pos,2j) & lt ^ t ^ cos (pos/& lt 10000 ^ (2j/d)) & lt & gt cos (t/& lt 10000 ^ (2 j/d)).
In this embodiment, Adaptive Computation Time (ACT) may be used to adjust the number of Computation steps, while ACT is independent for each location in the artificial intelligence model incorporating the ACT mechanism.
In this embodiment, the contents described in steps S204 to S205 may form a step of "encoding the first position encoding vector according to the multi-head attention mechanism included in the artificial intelligence model to obtain the encoded text", so that the technical effects brought by the contents described in steps S204 to S205 and the technical problems solved by the contents are the same as the above-mentioned forming steps, and no further description is given in this embodiment.
S206, decoding the coded text according to a multi-head attention mechanism included by the artificial intelligence model and a sequence mask algorithm included by the artificial intelligence model to obtain a decoding preposed text.
In this embodiment, the artificial intelligence model may include two mask algorithms: padding mask algorithm (Padding mask) and Sequence mask algorithm (Sequence mask). The Padding mask operation means that the input data sequences are not necessarily the same length for each batch, so that the input sequences need to be aligned, and 0 is filled behind the shorter data sequence as a supplementary length. The Sequence mask is used for enabling a decoder not to acquire data information after the time t, enabling the decoder to output an upper triangular matrix only according to the output before the time t and not according to the output after the time t, wherein the values of the upper triangle are all 1, and the values of the lower triangle and the diagonal line are 0; then, the matrix is combined on each data sequence to mask all data information after t.
And S207, decoding the decoding preposed text according to a multi-head attention mechanism included by the artificial intelligence model to obtain a decoding process text.
In this embodiment, this process may be understood as a decoding process corresponding to encoding.
And S208, inputting the decoding process text into a transition function included in the artificial intelligent model to perform circular operation to obtain a decoding text.
In this embodiment, the decoder of the artificial intelligence model is composed of an Embedding layer (Embedding layer), a position coding layer, a plurality of decoding layers, and 2 full-connection layers. Wherein the plurality of decoding layers comprises a mask multi-head attention layer, a multi-head attention layer; where the value vector and key vector receive the encoder output as inputs and the query vector receives the output from the masked multi-headed attention layer.
In this embodiment, the decoded text includes a plurality of decoding features, and the plurality of decoding features may be combined into the dialog text.
S209, classifying the decoded text according to the classifier included in the artificial intelligence model to obtain the text vector probability.
In this embodiment, the text vector probability is a screening condition of the above-mentioned decoding features. The filtering condition may be understood as a condition for selecting a certain word at a certain text position.
And S210, generating a text according to the decoded word vector and the text vector probability included by the artificial intelligence model to obtain a dialog text.
In the present embodiment, the dialog text is a reply text corresponding to the communication text.
In this embodiment, the decoded word vector is obtained by embedding the input text and is used to restore the reply text. The source of the decoded word vector is the target text, i.e. the decoded text (predetermined text library).
Referring to fig. 7, fig. 7 is a schematic structural diagram of an artificial intelligence model provided in this embodiment.
Therefore, by implementing the dialog text generation method described in fig. 2, after the communication text is received, the response process of the communication text can be completed through the artificial intelligence model, wherein the artificial intelligence model includes an encoder, a decoder and a classifier, which can realize the deep recognition, the response feature generation and the dialog text generation of the communication text, so that the dialog text can be accurately generated, the intelligent dialog problem of the intelligent software or the intelligent robot can be solved, and the intelligence of the intelligent software or the intelligent robot at present can be increased.
Example 3
Referring to fig. 3, fig. 3 is a schematic structural diagram of a dialog text generation apparatus according to an embodiment of the present application. Wherein, this dialog text generation device includes:
a receiving unit 310, configured to receive an input alternating text;
the encoding unit 320 is configured to encode the alternating-current text according to a preset artificial intelligence model to obtain an encoded text;
the decoding unit 330 is configured to decode the encoded text according to the artificial intelligence model to obtain a decoded text;
and the generating unit 340 is configured to classify the decoded text according to the classifier included in the artificial intelligence model, so as to obtain a dialog text.
In this embodiment, for the explanation of the dialog text generation device, reference may be made to the description in embodiment 1 or embodiment 2, and details are not repeated in this embodiment.
Therefore, by implementing the dialog text generation device described in fig. 3, the targeted and efficient work can be realized through the cooperative cooperation among a plurality of units, which is beneficial to the division and cooperation capability of the text generation device; meanwhile, the dialog text generation device can divide the artificial intelligence model into a plurality of units, and the effect improvement of respective functions is realized; in addition, the dialog text generation device can complete the reply process of the communication text through an artificial intelligence model after receiving the communication text; the artificial intelligence model comprises an encoder, a decoder and a classifier, and can realize the deep recognition of the communication text, the generation of the response characteristics and the generation of the conversation text, so that the accurate generation of the conversation text can be realized, the intelligent conversation problem of intelligent software or an intelligent robot can be solved, and the intelligence of the current intelligent software or the intelligent robot is improved.
Example 4
Referring to fig. 4, fig. 4 is a schematic structural diagram of another dialog text generation apparatus according to an embodiment of the present application. The schematic structural diagram of the dialog text generation apparatus depicted in fig. 4 is modified from the schematic structural diagram of the dialog text generation apparatus depicted in fig. 3. Wherein the encoding unit 320 includes:
the conversion subunit 321 is configured to perform word vector conversion on the alternating-current text according to a word embedding algorithm included in a preset artificial intelligence model to obtain an alternating-current word vector;
a first encoding subunit 322, configured to perform position encoding on the alternating-current word vector to obtain a first position-encoded vector;
and the second encoding subunit 323 is configured to encode the first position encoding vector according to a multi-head attention mechanism included in the artificial intelligence model, so as to obtain an encoded text.
As an alternative implementation, the encoding unit 320 further includes an encoding loop sub-unit 324, wherein,
the second encoding subunit 323 is configured to encode the first position encoding vector according to a multi-head attention mechanism included in the artificial intelligence model, so as to obtain an encoding process text;
and the encoding circulation subunit 324 is configured to input the encoding process text into the transition function included in the artificial intelligence model to perform circulation operation, so as to obtain an encoded text.
As an alternative embodiment, the decoding unit 330 includes:
the first decoding subunit 331, configured to decode the encoded text according to the multi-head attention mechanism included in the artificial intelligence model and the sequence mask algorithm included in the artificial intelligence model, to obtain a decoded pre-text;
the second decoding subunit 332, configured to decode the decoding pre-text according to the multi-head attention mechanism included in the artificial intelligence model, to obtain a decoding process text;
and the decoding cycle subunit 333 is configured to input the decoding process text into a transition function included in the artificial intelligence model to perform a cycle operation, so as to obtain a decoded text.
As an optional implementation, the generating unit 340 includes:
a classification subunit 341, configured to classify the decoded text according to the classifier included in the artificial intelligence model, so as to obtain a text vector probability;
the generating subunit 342 is configured to perform text generation according to the decoded word vectors and the text vector probabilities included in the artificial intelligence model, so as to obtain a dialog text.
In this embodiment, for the explanation of the dialog text generation device, reference may be made to the description in embodiment 1 or embodiment 2, and details are not repeated in this embodiment.
Therefore, by implementing the dialog text generation device described in fig. 4, the targeted and efficient work can be realized through the cooperative cooperation among a plurality of units, which is beneficial to the division and cooperation capability of the text generation device; meanwhile, the dialog text generation device can divide the artificial intelligence model into a plurality of units, and the effect improvement of respective functions is realized; in addition, the dialog text generation device can complete the reply process of the communication text through an artificial intelligence model after receiving the communication text; the artificial intelligence model comprises an encoder, a decoder and a classifier, and can realize the deep recognition of the communication text, the generation of the response characteristics and the generation of the conversation text, so that the accurate generation of the conversation text can be realized, the intelligent conversation problem of intelligent software or an intelligent robot can be solved, and the intelligence of the current intelligent software or the intelligent robot is improved.
An embodiment of the present application provides an electronic device, which includes a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute a dialog text generation method according to any one of embodiment 1 or embodiment 2 of the present application.
An embodiment of the present application provides a computer-readable storage medium, which stores computer program instructions, and when the computer program instructions are read and executed by a processor, the computer program instructions execute the dialog text generation method according to any one of embodiment 1 or embodiment 2 of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. A dialog text generation method, the method comprising:
receiving input alternating text;
coding the alternating current text according to a preset artificial intelligence model to obtain a coded text;
decoding the coded text according to the artificial intelligence model to obtain a decoded text;
and classifying the decoded text according to a classifier included in the artificial intelligence model to obtain a dialog text.
2. The dialog text generation method according to claim 1, wherein the step of encoding the interactive text according to a preset artificial intelligence model to obtain an encoded text comprises:
performing word vector conversion on the alternating text according to a word embedding algorithm included in a preset artificial intelligence model to obtain an alternating word vector;
carrying out position coding on the alternating word vector to obtain a first position coding vector;
and coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coded text.
3. The method according to claim 2, wherein the step of encoding the first position-coding vector according to a multi-attention mechanism included in the artificial intelligence model to obtain the encoded text comprises:
coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coding process text;
and inputting the coding process text into a transition function included in the artificial intelligence model to perform circular operation to obtain a coding text.
4. The dialog text generation method according to claim 1, wherein the step of decoding the encoded text according to the artificial intelligence model to obtain a decoded text comprises:
decoding the coded text according to a multi-head attention mechanism included by the artificial intelligence model and a sequence mask algorithm included by the artificial intelligence model to obtain a decoded pre-text;
decoding the decoding preposed text according to a multi-head attention mechanism included by the artificial intelligence model to obtain a decoding process text;
and inputting the decoding process text into a transition function included in the artificial intelligence model to perform circular operation to obtain a decoding text.
5. The method according to claim 1, wherein the step of classifying the decoded text according to the classifier included in the artificial intelligence model to obtain the dialog text comprises:
classifying the decoded text according to a classifier included in the artificial intelligence model to obtain text vector probability;
and generating a text according to the decoded word vector and the text vector probability included by the artificial intelligence model to obtain a dialog text.
6. A dialog text generation apparatus, characterized in that the dialog text generation apparatus comprises:
the receiving unit is used for receiving the input alternating text;
the encoding unit is used for encoding the alternating-current text according to a preset artificial intelligence model to obtain an encoded text;
the decoding unit is used for decoding the coded text according to the artificial intelligence model to obtain a decoded text;
and the generating unit is used for classifying the decoded text according to the classifier included by the artificial intelligence model to obtain the dialog text.
7. The dialog text generation device of claim 6 wherein the encoding unit comprises:
the conversion subunit is used for carrying out word vector conversion on the alternating text according to a word embedding algorithm included by a preset artificial intelligence model to obtain an alternating word vector;
the first coding subunit is used for carrying out position coding on the alternating word vector to obtain a first position coding vector;
and the second coding subunit is used for coding the first position coding vector according to a multi-head attention mechanism included by the artificial intelligence model to obtain a coded text.
8. The dialog text generation device of claim 6 wherein the decoding unit comprises:
the first decoding subunit is configured to decode the encoded text according to a multi-head attention mechanism included in the artificial intelligence model and a sequence mask algorithm included in the artificial intelligence model, so as to obtain a decoded pre-text;
the second decoding subunit is configured to decode the decoding pre-text according to a multi-head attention mechanism included in the artificial intelligence model, so as to obtain a decoding process text;
and the decoding circulation subunit is used for inputting the decoding process text into the transition function included in the artificial intelligence model to perform circulation operation, so as to obtain a decoding text.
9. An electronic device, characterized in that the electronic device comprises a memory for storing a computer program and a processor for executing the computer program to cause the electronic device to perform the dialog text generation method of any of claims 1 to 5.
10. A readable storage medium having stored thereon computer program instructions which, when read and executed by a processor, perform the dialog text generation method of any of claims 1 to 5.
CN202010179197.5A 2020-03-12 2020-03-12 Dialog text generation method and device Withdrawn CN113392193A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010179197.5A CN113392193A (en) 2020-03-12 2020-03-12 Dialog text generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010179197.5A CN113392193A (en) 2020-03-12 2020-03-12 Dialog text generation method and device

Publications (1)

Publication Number Publication Date
CN113392193A true CN113392193A (en) 2021-09-14

Family

ID=77616173

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010179197.5A Withdrawn CN113392193A (en) 2020-03-12 2020-03-12 Dialog text generation method and device

Country Status (1)

Country Link
CN (1) CN113392193A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190130273A1 (en) * 2017-10-27 2019-05-02 Salesforce.Com, Inc. Sequence-to-sequence prediction using a neural network model
CN109978141A (en) * 2019-03-28 2019-07-05 腾讯科技(深圳)有限公司 Neural network model training method and device, natural language processing method and apparatus
CN110032633A (en) * 2019-04-17 2019-07-19 腾讯科技(深圳)有限公司 More wheel dialog process method, apparatus and equipment
CN110046248A (en) * 2019-03-08 2019-07-23 阿里巴巴集团控股有限公司 Model training method, file classification method and device for text analyzing
CN110399460A (en) * 2019-07-19 2019-11-01 腾讯科技(深圳)有限公司 Dialog process method, apparatus, equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190130273A1 (en) * 2017-10-27 2019-05-02 Salesforce.Com, Inc. Sequence-to-sequence prediction using a neural network model
CN110046248A (en) * 2019-03-08 2019-07-23 阿里巴巴集团控股有限公司 Model training method, file classification method and device for text analyzing
CN109978141A (en) * 2019-03-28 2019-07-05 腾讯科技(深圳)有限公司 Neural network model training method and device, natural language processing method and apparatus
CN110032633A (en) * 2019-04-17 2019-07-19 腾讯科技(深圳)有限公司 More wheel dialog process method, apparatus and equipment
CN110399460A (en) * 2019-07-19 2019-11-01 腾讯科技(深圳)有限公司 Dialog process method, apparatus, equipment and storage medium

Similar Documents

Publication Publication Date Title
US11741109B2 (en) Dialogue system, a method of obtaining a response from a dialogue system, and a method of training a dialogue system
CN109508377A (en) Text feature, device, chat robots and storage medium based on Fusion Model
CN110163181B (en) Sign language identification method and device
CN110647612A (en) Visual conversation generation method based on double-visual attention network
CN107836000A (en) For Language Modeling and the improved artificial neural network of prediction
CN110781306B (en) English text aspect layer emotion classification method and system
CN110796160A (en) Text classification method, device and storage medium
CN109740158B (en) Text semantic parsing method and device
CN111930918B (en) Cross-modal bilateral personalized man-machine social interaction dialog generation method and system
CN109344242B (en) Dialogue question-answering method, device, equipment and storage medium
JP7417679B2 (en) Information extraction methods, devices, electronic devices and storage media
CN111241828A (en) Intelligent emotion recognition method and device and computer readable storage medium
CN112380319A (en) Model training method and related device
JP7229345B2 (en) Sentence processing method, sentence decoding method, device, program and device
CN113705315B (en) Video processing method, device, equipment and storage medium
CN112347223A (en) Document retrieval method, document retrieval equipment and computer-readable storage medium
CN114567332A (en) Text secondary compression method, device and equipment and computer readable storage medium
CN111339780A (en) Word processing method and device based on multitask model
CN111145914B (en) Method and device for determining text entity of lung cancer clinical disease seed bank
CN110472746B (en) Artificial intelligence-based coding prediction method and system
CN115687567A (en) Method for searching similar long text by short text without marking data
Arora et al. Comparative question answering system based on natural language processing and machine learning
CN113221553A (en) Text processing method, device and equipment and readable storage medium
CN111241820A (en) Bad phrase recognition method, device, electronic device, and storage medium
US20220198149A1 (en) Method and system for machine reading comprehension

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WW01 Invention patent application withdrawn after publication

Application publication date: 20210914

WW01 Invention patent application withdrawn after publication