WO2020151175A1 - 文本生成方法、装置、计算机设备及存储介质 - Google Patents

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

Info

Publication number
WO2020151175A1
WO2020151175A1 PCT/CN2019/092519 CN2019092519W WO2020151175A1 WO 2020151175 A1 WO2020151175 A1 WO 2020151175A1 CN 2019092519 W CN2019092519 W CN 2019092519W WO 2020151175 A1 WO2020151175 A1 WO 2020151175A1
Authority
WO
WIPO (PCT)
Prior art keywords
word vector
text
attention matrix
neural network
preset
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.)
Ceased
Application number
PCT/CN2019/092519
Other languages
English (en)
French (fr)
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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Publication of WO2020151175A1 publication Critical patent/WO2020151175A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/40Processing or translation of natural language
    • G06F40/55Rule-based translation
    • G06F40/56Natural language generation
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • G06F40/211Syntactic parsing, e.g. based on context-free grammar [CFG] or unification grammars
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/40Processing or translation of natural language
    • G06F40/42Data-driven translation
    • G06F40/44Statistical methods, e.g. probability models
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/09Supervised learning
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/313Selection or weighting of terms for indexing
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/36Creation of semantic tools, e.g. ontology or thesauri
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the technical field of text generation, and in particular to a text generation method, device, computer equipment, and computer-readable storage medium.
  • Text generation refers to the generation of new character text given language model parameters and text fragments.
  • the traditional text generation model is based on the recurrent neural network.
  • the recurrent neural network (Recurrent Neural Network, RNN) is a type of sequence (Sequence) data as input, recursive in the evolution direction of the sequence and all nodes (recurrent units) Recursive Neural Network (Recursive Neural Network) that forms a closed loop by chain connection. Since the recurrent neural network model uses a sequence to recursively generate text, the training efficiency of the text generation model is low.
  • the embodiments of the present application provide a text generation method, device, computer equipment, and computer-readable storage medium, which can solve the problem of low training efficiency during text generation model training in the traditional technology.
  • an embodiment of the present application provides a text generation method, the method includes: obtaining an initial text for text generation and a preset prediction vocabulary; and performing word embedding on the initial text and the preset prediction vocabulary respectively To convert the initial text into a first word vector and convert the preset prediction vocabulary into a second word vector; to obtain the first word vector and the second word vector through a corresponding convolutional neural network, respectively The first attention matrix of the first word vector and the second attention matrix of the second word vector; multiply the first attention matrix and the second attention matrix to obtain a third attention matrix Matrix; the third attention matrix is normalized and matched with a preset predicted vocabulary to generate predicted text.
  • an embodiment of the present application also provides a text generation device, wherein the device includes: an acquisition unit, configured to acquire initial text and preset prediction vocabulary for text generation; and a conversion unit, configured to convert the The initial text and the preset predicted vocabulary are respectively embedded in words to convert the initial text into a first word vector and the preset predicted vocabulary into a second word vector; a convolution unit is used to convert the first word vector A word vector and the second word vector obtain the first attention matrix of the first word vector and the second attention matrix of the second word vector through the corresponding convolutional neural network respectively; the unit is used to obtain Multiply the first attention matrix and the second attention matrix to obtain a third attention matrix; a matching unit for performing normalization of the third attention matrix with a preset prediction vocabulary Match to generate predictive text.
  • the device includes: an acquisition unit, configured to acquire initial text and preset prediction vocabulary for text generation; and a conversion unit, configured to convert the The initial text and the preset predicted vocabulary are respectively embedded in words to convert the initial text into a first word vector and the preset predicted
  • an embodiment of the present application also provides a computer device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the text generation method when the computer program is executed.
  • the embodiments of the present application also provide a computer-readable storage medium, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the text generation method.
  • FIG. 1 is a schematic diagram of an application scenario of a text generation method provided by an embodiment of the application
  • FIG. 2 is a schematic flowchart of a text generation method provided by an embodiment of the application.
  • FIG. 3 is a schematic diagram of word vectors in a text generation method provided by an embodiment of the application.
  • FIG. 4 is a schematic diagram of a corresponding model in the text generation method provided by an embodiment of the application.
  • FIG. 5 is a schematic diagram of a sub-process in the text generation method provided by an embodiment of the application.
  • FIG. 6 is a schematic block diagram of a text generation apparatus provided by an embodiment of the application.
  • FIG. 7 is another schematic block diagram of a text generation apparatus provided by an embodiment of the application.
  • FIG. 8 is a schematic block diagram of a computer device provided by an embodiment of the application.
  • FIG. 1 is a schematic diagram of an application scenario of a text generation method provided by an embodiment of the application.
  • the application scenarios include:
  • the terminal may be an electronic device such as a notebook computer, a tablet computer, or a desktop computer.
  • the terminal application environment shown in FIG. 1 is also It can be replaced with computer equipment such as servers.
  • the application environment in Figure 1 is a server
  • the server can be a server cluster or a cloud server.
  • the server cluster can also adopt a distributed system, and the servers of the distributed system can include a master server and a slave server, so that the master server uses the obtained initial text to perform the steps of the text generation method, and the slave server can be used to store a large amount of generated data.
  • each subject in Fig. 1 The working process of each subject in Fig. 1 is as follows: the terminal obtains the initial text and the preset predicted vocabulary for text generation; embeds the initial text and the preset predicted vocabulary to convert the initial text into the first Word vector and converting the preset prediction vocabulary into a second word vector; respectively obtaining the first attention of the first word vector through the corresponding convolutional neural network of the first word vector and the second word vector Force matrix and the second attention matrix of the second word vector; multiply the first attention matrix and the second attention matrix to obtain a third attention matrix; add the third attention matrix After being normalized, it is matched with a preset prediction vocabulary to generate a prediction text.
  • FIG. 1 only shows a desktop computer as a terminal.
  • the type of terminal is not limited to that shown in FIG. 1.
  • the terminal may also be an electronic device such as a mobile phone, a notebook computer, or a tablet computer.
  • the application scenarios of the above text generation method are only used to illustrate the technical solutions of this application, and are not used to limit the technical solutions of this application.
  • Fig. 2 is a schematic flowchart of a text generation method provided by an embodiment of the application.
  • the text generation method is applied to the terminal in FIG. 1 to complete all or part of the functions of the text generation method.
  • Figure 2 is a schematic flowchart of a text generation method provided by an embodiment of the present application
  • Figure 3 is a schematic diagram of a word vector in the text generation method provided by an embodiment of the application
  • a corresponding model diagram in the text generation method As shown in Figure 2, the method includes the following steps S210-S250:
  • the initial text refers to the text input by the user through the input device.
  • the content input by the user next is predicted based on the content input by the user to generate recommended text content matched with the input initial text, thereby improving the text input efficiency of the user.
  • the preset prediction vocabulary refers to a preset vocabulary selection range for generating prediction text.
  • the preset prediction vocabulary can be updated according to the content input by the user, and the preset prediction vocabulary is updated by recording and storing the user's common language to improve the accuracy of prediction, thereby improving the efficiency of text generation.
  • the embodiment of the present application is a text generation model based on a multi-scale parallel convolutional neural network, that is, the convolutional neural network is used to separately analyze the input initial text vocabulary to obtain the text information of the initial text, and analyze the preset prediction vocabulary
  • the correlation between the initial text is normalized by convolving the word vector of the initial text, then the first attention matrix and the preset prediction vocabulary are convolved and then normalized to obtain the second attention matrix.
  • the first attention matrix and the second attention matrix are multiplied to obtain the word vector of the predicted text, and then the word vector of the predicted text is normalized and the preset predicted vocabulary is matched to generate the predicted text.
  • the terminal obtains the initial text for text generation, for example, the text input by the user through the input device.
  • the text generation model predicts the predicted text associated with the input text from the preset predicted vocabulary according to the input text through the convolutional neural network, the predicted text It can be a predicted vocabulary, it can also be a predicted sentence or a paragraph, and the output is the text generation result.
  • S220 Perform word embedding on the initial text and the preset predicted vocabulary respectively to convert the initial text into a first word vector and convert the preset predicted vocabulary into a second word vector.
  • word embedding which is Word Embedding in English
  • Words with similar meanings have similar representations. It is a general term for the method of mapping words to real number vectors.
  • the structure layer where the word embedding is located is called the word embedding layer.
  • Word embedding layer or embedding layer for short, and Embedding layer in English.
  • Word embedding is a type of technology, which means that a single word is represented as a real number vector in a predefined vector space, and each word is mapped to a vector.
  • FIG. 3 is a schematic diagram of a word vector in a text generation method provided by an embodiment of the application.
  • the terminal converts the initial text and the preset prediction vocabulary into corresponding word vectors through the word embedding layer in the text generation model, that is, encodes the input natural language into word vectors.
  • the initial text is transformed into a first word vector
  • the preset predicted vocabulary is transformed into a second word vector, in preparation for text generation.
  • Word vectors are more than 100 times faster. If the pre-trained word vector is used, it is divided into Static method and No-static method.
  • Static method means that the parameters of the word vector are no longer adjusted during the process of training text generation.
  • No-static method is used in the training process of the text generation model. Adjust the parameters of the word vector, so the result of the No-static method is better than the result of the Static method.
  • Embedding layer embedding layer
  • a trained preset word vector dictionary can be used to embed the initial text to convert the initial text into a word vector.
  • the word vector can be a Word2Vec pre-trained word vector, that is, each vocabulary has a corresponding vector representation, which can express vocabulary information in the form of data, and the word vector dimension can be 300.
  • Word2vec which is Word to vector in English, is a software tool for training word vectors. It is used to generate related models of word vectors.
  • the automatic training of word vectors can be implemented through the Gensim library in Python.
  • convolutional neural network English is Convolutional Neural Networks, referred to as CNN, is a type of feedforward neural network (Feedforward Neural Networks) that contains convolution or related calculations and has a deep structure. It is a representative of deep learning (Deep Learning) One of the algorithms. Because convolutional neural networks can perform translation invariant classification (English: Shift-Invariant Classification), they are also called “translation invariant artificial neural networks (English: Shift-Invariant Artificial Neural Networks, referred to as SIANN).
  • SIANN Shift-Invariant Artificial Neural Networks
  • Attention also known as attention mechanism, or attention model, or attention structure, English is Attention Model.
  • the attention model in natural language processing draws on the concept of human attention.
  • visual attention is a brain signal processing mechanism unique to human vision. Human vision can quickly scan the global image to obtain the target area that needs to be focused. , which is commonly referred to as the focus of attention, and then put more attention resources in this area to obtain more detailed information about the target that needs to be paid attention to, and suppress other useless information. Human visual attention greatly improves vision The efficiency and accuracy of information processing.
  • the attention in the embodiments of this application is essentially similar to human selective visual attention, and the core goal is to select information that is more critical to the current task goal from a large number of information.
  • w and b respectively represent the parameters of the linear relationship between x and y, and w and b can be adjusted during the training process.
  • the attention matrix refers to the matrix after the weights are allocated in the matrix.
  • the function of the convolutional layer is to extract features from the input data. It contains multiple convolution kernels. Each element of the convolution kernel corresponds to a weight coefficient and a deviation, in the form of a matrix. Convolution is performed, so the attention matrix is generated after convolution and weight distribution.
  • the terminal after the terminal receives the initial text input by the user, the initial text is word-embedded through the word embedding layer to obtain the first word vector, and then the terminal uses the first convolutional layer in the convolutional layer to pair
  • the word vector is convolved, that is, the first word vector is convolved by a first convolutional neural network and normalized by the Softmax function to obtain the first word vector probability of the first word vector,
  • the first word vector is convolved by the first convolutional neural network in the first convolution layer to obtain a convolved first word vector, and the probability of the first word vector and the convolution first word
  • the vectors are multiplied to get the first attention matrix.
  • the terminal After receiving the preset prediction vocabulary, the terminal performs word embedding on the preset prediction vocabulary through the word embedding layer to obtain the second word vector, and then the terminal performs word embedding on the second word vector through the second convolutional layer in the convolutional layer.
  • the word vector is convolved, that is, the second word vector is convolved by the second convolutional neural network and normalized by the Softmax function to obtain the second word vector probability of the second word vector, and pass
  • the second convolutional neural network in the second convolutional layer convolves the second word vector to obtain a convolved second word vector, and compares the probability of the second word vector with the convolution second word vector Multiply by to get the second attention matrix.
  • matrix multiplication refers to matrix multiplication
  • English is Matrixmultiplication, which refers to general matrix product.
  • the first attention matrix and the second attention matrix are multiplied to obtain a third attention matrix.
  • normalization is a way to simplify calculations, that is, a dimensional expression is transformed into a dimensionless expression and becomes a scalar.
  • the English name is Normalization.
  • the normalization method has two forms, one is to change the number to a decimal between (0, 1), and the other is to change the dimensional expression to a dimensionless expression. It is mainly proposed for the convenience of data processing. It is more convenient and faster to map the data to the range of 0 to 1.
  • Commonly used normalization functions include the Softmax function.
  • the Softmax function or normalized exponential function, is an extension of the logic function, which can "compress" a K-dimensional vector z containing any real number into another K-dimensional real vector ⁇ (z), so that The range of each element is between (0,1), and the sum of all elements is 1.
  • the Softmax function is actually the logarithmic normalization of the gradient of the finite item discrete probability distribution.
  • the third attention matrix is normalized, the weight of each vector in the third attention matrix, or the probability of each vector, is obtained.
  • the third attention The matrix is normalized by the Softmax function to obtain the third word vector, and then the third word vector is matched with each vector of the preset prediction vocabulary, thereby converting each vector in the third attention matrix into each of the preset prediction vocabulary Natural language vocabulary to generate predictive text.
  • the output of the generated predictive text is processed by the attention mechanism in the text generation model. The output is the generated text content.
  • the text generation model passes through the convolutional layer, the first attention layer, and the second attention layer.
  • the attention layer constructs the output content, where the second attention layer is a fully connected network structure, and the output function is Softmax, which is used to limit the range of attention so that the data adjusted by the attention weight is input into the convolutional layer to obtain the prediction object And match the word vector with a dictionary composed of preset prediction words to determine the predicted text to be output.
  • the text generation model must be trained first.
  • the loss function of the text generation model is cross-entropy, and the training method is ADAM learning rate 0.001, where ADAM , English is Adaptive Moment Estimation, which is adaptive moment estimation.
  • ADAM Adaptive Moment Estimation
  • the learning rate in English, is the learning rate, also known as the learning rate, which is used to control the learning progress of the model.
  • the training of the neural network is implemented through the Tensorflow library in Python.
  • the trained text generation model can be used for user input word prediction.
  • the initial text and the preset predicted vocabulary for text generation are obtained, and the initial text and the preset predicted vocabulary are respectively embedded in words to convert the initial text into the first A word vector and converting the preset prediction vocabulary into a second word vector, and the first word vector and the second word vector are respectively passed through a corresponding convolutional neural network to obtain the first attention of the first word vector Force matrix and the second attention matrix of the second word vector, multiply the first attention matrix and the second attention matrix to obtain a third attention matrix, and the third attention matrix
  • it is matched with the preset predicted vocabulary to generate the predicted text, and then according to the input text, the information is refined through the convolutional neural network, and the predicted text with strong association attributes is generated within the preset predicted vocabulary.
  • the text generation model established in the embodiment of the present application adopts the parallel computing characteristics of the multi-scale convolutional neural network with higher training efficiency.
  • the first word vector and the second word vector are respectively passed through a corresponding convolutional neural network to obtain the first word vector of the first word vector.
  • the steps of an attention matrix and the second attention matrix of the second word vector include:
  • S510 Perform convolution on the first word vector by a first convolutional neural network, and obtain the first word vector probability of the first word vector after normalization;
  • S540 Convolve the second word vector through a second convolutional neural network and obtain a second word vector probability of the second word vector after normalization;
  • the terminal needs to first establish a first convolutional neural network and a second convolutional neural network to capture the information of the word vector through the convolutional neural network to obtain the word vector relationship between the word vectors.
  • the text generation model needs to perform the next input prediction based on the content that the user has input. Since input prediction may depend on one or more words that have been input, the text generation model sets up a multi-dimensional convolution kernel to capture local information of the input text.
  • the text generation model includes two parallel convolutional layers, the first convolutional layer and the second convolutional layer, that is, the convolutional layer to which the first convolutional neural network belongs and the second convolutional neural network Convolutional layer.
  • Each convolutional layer in the first convolutional layer and the second convolutional layer includes two parallel sub-convolutional layers. Among them, one sub-convolutional layer in each convolutional layer is mapped by the Softmax function After that, it is multiplied by another sub-convolutional layer, and each convolutional layer is point-multiplied by establishing two sub-convolution kernels to achieve information extraction. Among them, dot multiplication is also called the inner product and quantity product of vectors.
  • the text generation model has preset predicted words in advance. For example, 1000 words have been established as optional predicted words, and the preset predicted words are converted into second words by word vector conversion in the embedding layer.
  • the text generation model uses the word embedding layer to convert text and word vectors, and enters the first convolutional layer to which the first convolutional neural network belongs, through the first convolution
  • the neural network convolves the first word vector and normalizes it by the Softmax function to obtain the first word vector probability of the first word vector.
  • the first word vector is calculated by the first convolutional neural network.
  • the vector is convolved to obtain a convolved first word vector, and the first word vector probability and the convolved first word vector are multiplied to obtain a first attention matrix.
  • the height of the first convolutional layer may include two types of convolutional neural networks of 1 dimension and 3 dimensions, and each type of convolutional neural network has 128 channels.
  • the first convolutional neural network before the normalization of the Softmax function in the first convolutional layer and the first convolutional neural network that obtains the convolutional first word vector in the first convolutional layer may be the same or different.
  • the Softmax in the first convolutional layer may both be a 1-dimensional convolutional neural network or a 3-dimensional convolution Product neural network.
  • the first convolutional neural network before the normalization of the Softmax function in the first convolutional layer is different from the first convolutional neural network that obtains the first convolutional word vector in the first convolutional layer, for example, the first convolution
  • the first convolutional neural network before the normalization of the Softmax function in the layer is a 3-dimensional convolutional neural network
  • the convolutional neural network that obtains the first convolutional word vector in the first convolutional layer is a 1-dimensional convolutional neural network .
  • the terminal receives the preset predicted vocabulary, it embeds the preset predicted vocabulary through the word embedding layer to obtain the second word vector, and then the terminal passes the volume
  • the second convolutional layer in the buildup layer convolves the second word vector, that is, convolves the second word vector through the second convolutional neural network and normalizes it by the Softmax function to obtain the State the second word vector probability of the second word vector, and at the same time convolve the second word vector through the second convolutional neural network in the second convolutional layer to obtain the convolved second word vector, The probability of the two word vectors is multiplied by the convolved second word vector to obtain a second attention matrix.
  • the goal of the embodiments of this application is to predict input words. Since the initial text input by the text generation model has the characteristics of variable length, the text generation model outputs two parts through variable length training text and optional preset prediction words Matrix, that is, the first attention matrix and the second attention matrix, and multiply these two parts of the matrix to obtain the third attention matrix, and the third attention matrix is mapped to the Softmax function, and the third attention matrix is The vector of, in descending order of probability, outputs words with higher probability as predicted words to generate predicted text, so as to increase the probability of text output accuracy and improve the efficiency of user input.
  • Matrix that is, the first attention matrix and the second attention matrix
  • the step of performing convolution on the first word vector by a first convolutional neural network and normalizing to obtain the first word vector probability of the first word vector includes:
  • the step of performing convolution on the second word vector by a second convolutional neural network and normalization to obtain the second word vector probability of the second word vector includes:
  • the second word vector is convolved by a second convolutional neural network, and the short-term information and long-term information of the second word vector are captured after normalization to obtain the second word vector probability.
  • the text generation model sets up a multi-dimensional convolution kernel to capture the local information of the input text
  • the local information refers to the information of the word vector
  • the information of the word vector refers to the difference between the vocabulary sequences included in the input text.
  • Associated information can also be understood as the sequence information of the input text, used to describe the contextual relationship of the input text, and the combination of words to form a specific meaning.
  • the probability of the above-mentioned "cat” and “dog” collocation is higher than the probability of " ⁇ ” and "love” collocation.
  • the fixed idiom in Chinese reflects the corresponding contextual relationship and sequence information, such as , When it comes to "a journey of a thousand miles", it is usually accompanied by text content such as "beginning with a single step”.
  • the word vector information includes short-term information and long-term information.
  • Short-term information refers to sequence information below a preset number of words
  • short-term information can also be called short-term sequence information
  • long-term information refers to a preset number and prediction. Assuming sequence information between words above the number, long-term information can be called long-term sequence information.
  • short-term information is information in a text embodied in a vocabulary of one word or two words
  • long-term information is sequence information in a text embodied in a vocabulary of three words, four words, and four words.
  • the first word vector is convolved by the first convolutional neural network and the short-term information and long-term information of the first word vector are captured after normalization to obtain the probability of the first word vector, and the second convolutional neural network
  • the network convolves the second word vector and after normalization, it captures the short-term information and long-term information of the second word vector to obtain the second word vector probability.
  • the short-term information and the long-term information are calculated through the convolutional neural network.
  • the method further includes:
  • the step of matching the third word vector with a preset predicted vocabulary to generate predicted text includes:
  • the preset number of third word vectors that have been filtered out are matched with a preset prediction vocabulary to generate a preset number of prediction texts.
  • a preset number of third word vectors are filtered out according to the probability of the third word vector from high to low, and then the preset number of third word vectors selected are filtered out.
  • the three-word vector is matched with a preset predicted vocabulary to generate a preset number of predicted texts. For example, it is set in advance to generate 5 predicted words, and the 5 third word vectors are filtered out according to the probability of the third word vector from high to low, and then the 5 third word vectors selected are combined with the preset predicted words.
  • Matching generates a predicted text of 5 words, and outputs the generated text composed of 5 predicted words, so that it is not necessary to match and output all the predicted texts, which reduces the amount of data processing and improves the efficiency of text prediction.
  • the method further includes:
  • the generated predicted text is displayed in horizontal or vertical rows according to the probability of the corresponding third word vector from high to low, that is, the probability of the third word vector corresponding to the third word vector is displayed in horizontal or vertical rows from high to low.
  • the predictive text of the preset amount is displayed in a vertical row. For example, it is set in advance to generate 5 predicted words, and the 5 third word vectors are filtered out according to the probability of the third word vector from high to low, and then the 5 third word vectors selected are combined with the preset predicted words. Match to generate 5 words of predicted text, and output the generated text composed of 5 words of predicted words.
  • the generated 5 words of predicted text are arranged horizontally or vertically according to the probability of the corresponding third word vector. The way of row display.
  • FIG. 6 is a schematic block diagram of a text generating apparatus provided by an embodiment of the application.
  • an embodiment of the present application also provides a text generation device.
  • the text generation device includes a unit for executing the above-mentioned text generation method, and the device can be configured in a computer device such as a terminal or a server.
  • the text generation device 600 includes an acquisition unit 601, a conversion unit 602, a convolution unit 603, an obtaining unit 604 and a matching unit 605.
  • the obtaining unit 601 is configured to obtain the initial text and preset prediction vocabulary for text generation
  • a conversion unit 602 configured to perform word embedding on the initial text and the preset predicted vocabulary respectively to convert the initial text into a first word vector and convert the preset predicted vocabulary into a second word vector;
  • the convolution unit 603 is configured to obtain the first attention matrix of the first word vector and the second word vector through the corresponding convolutional neural network by the first word vector and the second word vector. Second attention matrix;
  • the obtaining unit 604 is configured to multiply the first attention matrix and the second attention matrix to obtain a third attention matrix
  • the matching unit 605 is configured to normalize the third attention matrix and match the preset predicted vocabulary to generate predicted text.
  • FIG. 7 is another schematic block diagram of the text generating apparatus provided by an embodiment of the application.
  • the convolution unit 603 includes:
  • the first convolution subunit 6031 is configured to convolve the first word vector through a first convolutional neural network and obtain the first word vector probability of the first word vector after normalization;
  • the second convolution subunit 6032 is configured to convolve the first word vector through the first convolutional neural network to obtain a convolved first word vector;
  • the first multiplication subunit 6033 is configured to multiply the probability of the first word vector and the first word vector of the convolution to obtain a first attention matrix
  • the third convolution subunit 6034 is configured to convolve the second word vector through a second convolutional neural network and obtain the second word vector probability of the second word vector after normalization;
  • a fourth convolution subunit 6035 configured to convolve the second word vector through the second convolutional neural network to obtain a convolved second word vector
  • the second multiplication subunit 6036 is configured to multiply the second word vector probability and the convolved second word vector to obtain a second attention matrix.
  • the first convolution subunit 6031 is configured to convolve the first word vector through a first convolutional neural network, and after normalization, capture the short-term information of the first word vector Information and long-term information to get the probability of the first word vector;
  • the third convolution subunit 6034 is configured to convolve the second word vector through a second convolutional neural network, and after normalization, capture the short-term information and long-term information of the second word vector to obtain the second Word vector probability.
  • the matching unit 605 includes:
  • a normalization subunit 6051 configured to normalize the third attention matrix to obtain a third word vector
  • the matching subunit 6053 is configured to match the third word vector with a preset prediction vocabulary to generate a prediction text.
  • the matching unit 605 further includes:
  • the screening subunit 6052 is configured to screen out a preset number of third word vectors according to the probability of the third word vector from high to low;
  • the matching subunit 6053 is configured to match the preset number of third word vectors that have been screened out with preset predicted words to generate a preset number of predicted texts.
  • the normalization subunit 6051 is used to normalize the third attention matrix by a Softmax function to obtain a third word vector.
  • the text generating device 600 further includes:
  • the display unit 606 is configured to display the preset number of predictive texts in a preset manner.
  • the division and connection of the units in the text generation device are only used for illustration.
  • the text generation device can be divided into different units as needed, or the units in the text generation device can be different.
  • the above-mentioned text generating apparatus can be implemented in the form of a computer program, and the computer program can be run on the computer device as shown in FIG. 8.
  • FIG. 8 is a schematic block diagram of a computer device according to an embodiment of the present application.
  • the computer device 800 may be a computer device such as a desktop computer or a server, or may be a component or component in other devices.
  • the computer device 800 includes a processor 802, a memory, and a network interface 805 connected through a system bus 801, where the memory may include a nonvolatile storage medium 803 and an internal memory 804.
  • the non-volatile storage medium 803 can store an operating system 8031 and a computer program 8032.
  • the processor 802 can execute one of the above-mentioned text generation methods.
  • the processor 802 is used to provide calculation and control capabilities to support the operation of the entire computer device 800.
  • the internal memory 804 provides an environment for the operation of the computer program 8032 in the non-volatile storage medium 803.
  • the processor 802 can execute one of the foregoing text generation methods.
  • the network interface 805 is used for network communication with other devices.
  • the structure shown in FIG. 8 is only a block diagram of part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 800 to which the solution of the present application is applied.
  • the specific computer device 800 may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
  • the computer device may only include a memory and a processor. In such an embodiment, the structures and functions of the memory and the processor are consistent with the embodiment shown in FIG. 8 and will not be repeated here.
  • the processor 802 is configured to run a computer program 8032 stored in the memory to implement the text generation method in the embodiment of the present application.
  • the processor 802 may be a central processing unit (Central Processing Unit, CPU), and the processor 802 may also be other general-purpose processors, digital signal processors (Digital Signal Processors, DSPs), Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor.
  • the embodiment of the present application also provides a computer-readable storage medium.
  • the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the steps of the text generation method described in the above embodiments.
  • the computer-readable storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (Read-Only Memory, ROM), a magnetic disk or an optical disk, and other computer-readable storage media that can store computer programs.
  • ROM Read-Only Memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Health & Medical Sciences (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Probability & Statistics with Applications (AREA)
  • Machine Translation (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例提供了一种文本生成方法、装置、计算机设备及计算机可读存储介质,属于文本生成技术领域。本申请实施例在实现文本生成时,通过获取进行文本生成的初始文本和预设预测词汇,将初始文本和预设预测词汇分别进行词嵌入以将初始文本转化为第一词向量和将预设预测词汇转化为第二词向量,将第一词向量和第二词向量分别通过对应的卷积神经网络获得第一词向量的第一注意力矩阵和第二词向量的第二注意力矩阵,将第一注意力矩阵和第二注意力矩阵相乘以得到第三注意力矩阵,将第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。

Description

文本生成方法、装置、计算机设备及存储介质
本申请要求于2019年1月23日提交中国专利局、申请号为201910064116.4、申请名称为“文本生成方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及文本生成技术领域,尤其涉及一种文本生成方法、装置、计算机设备及计算机可读存储介质。
背景技术
文本生成是指在给定语言模型参数和文本片段的情况下,产生新的字符文本。传统文本生成模型基于循环神经网络,其中,循环神经网络(Recurrent Neural Network,RNN)是一类以序列(Sequence)数据为输入,在序列的演进方向进行递归(Recursion)且所有节点(循环单元)按链式连接形成闭合回路的递归神经网络(Recursive Neural Network),由于循环神经网络模型是以序列采取递归方式进行文本生成,在文本生成模型训练时的训练效率较低。
发明内容
本申请实施例提供了一种文本生成方法、装置、计算机设备及计算机可读存储介质,能够解决传统技术中文本生成模型训练时训练效率比较低的问题。
第一方面,本申请实施例提供了一种文本生成方法,所述方法包括:获取进行文本生成的初始文本和预设预测词汇;将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测 文本。
第二方面,本申请实施例还提供了一种文本生成装置,其中,所述装置包括:获取单元,用于获取进行文本生成的初始文本和预设预测词汇;转化单元,用于将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;卷积单元,用于将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;得到单元,用于将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;匹配单元,用于将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
第三方面,本申请实施例还提供了一种计算机设备,其包括存储器及处理器,所述存储器上存储有计算机程序,所述处理器执行所述计算机程序时实现所述文本生成方法。
第四方面,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行所述文本生成方法。
附图说明
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的文本生成方法的应用场景示意图;
图2为本申请实施例提供的文本生成方法的流程示意图;
图3为本申请实施例提供的文本生成方法中词向量示意图;
图4为本申请实施例提供的文本生成方法中一个对应的模型示意图;
图5为本申请实施例提供的文本生成方法中一个子流程示意图;
图6为本申请实施例提供的文本生成装置的示意性框图;
图7为本申请实施例提供的文本生成装置的另一个示意性框图;以及
图8为本申请实施例提供的计算机设备的示意性框图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
请参阅图1,图1为本申请实施例提供的文本生成方法的应用场景示意图。所述应用场景包括:
(1)终端。图1所示终端上安装有应用程序,研发人员通过终端实现执行文本生成方法的步骤,所述终端可以为笔记本电脑、平板电脑或者台式电脑等电子设备,图1中所示的终端应用环境也可以更换为服务器等计算机设备。若图1中的应用环境为服务器,服务器可以为服务器集群或者云服务器。服务器集群又可以采用分布式系统,分布式系统的服务器又可以包括主服务器和从服务器,以使主服务器使用获得的初始文本执行文本生成方法的步骤,从服务器可以用于存储生成的大量数据。
图1中的各个主体工作过程如下:终端获取进行文本生成的初始文本和预设预测词汇;将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
需要说明的是,图1中仅仅示意出台式电脑作为终端,在实际操作过程中,终端的类型不限于图1中所示,所述终端还可以为手机、笔记本电脑或者平板电脑等电子设备,上述文本生成方法的应用场景仅仅用于说明本申请技术方案,并不用于限定本申请技术方案。
图2为本申请实施例提供的文本生成方法的示意性流程图。该文本生成方法应用于图1中的终端中以完成文本生成方法的全部或者部分功能。
请参阅图2至图4,图2是本申请实施例提供的文本生成方法的流程示意图,图3为本申请实施例提供的文本生成方法中词向量示意图;图4为本申请实施例提供的文本生成方法中一个对应的模型示意图。如图2所示,该方法包括以下步骤S210-S250:
S210、获取进行文本生成的初始文本和预设预测词汇。
其中,初始文本是指用户通过输入设备输入的文本。,比如,用户通过智能设备的触摸屏输入的内容,进而根据用户输入的内容对用户接下来输入的内容进行预测以生成与输入的初始文本搭配的推荐文本内容,进而提高用户的文本输入效率。
预设预测词汇是指预先设置的用于生成预测文本的词汇选择的范围。所述预设预测词汇可以根据用户输入的内容进行更新,通过记录并存储用户的常用语言更新预设预测词汇以提高预测的准确性,进而提高文本生成的效率。
具体地,本申请实施例是基于多尺度并行性的卷积神经网络的文本生成模型,也就是利用卷积神经网络分别分析输入的初始文本词汇获得初始文本的文本信息,并分析预设预测词汇之间的关联性,通过将初始文本的词向量卷积后进行归一化然后获得第一注意力矩阵和预设预测词汇进行卷积后进行归一化以获得第二注意力矩阵,将所述第一注意力矩阵与第二注意力矩阵相乘进而得到预测文本的词向量,再将预测文本的词向量进行归一化和预设预测词汇进行匹配以生成预测文本。终端获取进行文本生成的初始文本,比如,用户通过输入设备输入的文本,文本生成模型通过卷积神经网络根据输入文本从预设预测词汇中预测与输入文本相关联的预测文本,所述预测文本可以为预测词汇,也可以为预测的一句话或者一段话等,输出即为文本生成结果。
S220、将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量。
其中,词嵌入,英文为Word Embedding,是一种词的类型表示,具有相似意义的词具有相似的表示,是将词汇映射到实数向量的方法总称,词嵌入所在 的结构层称为词嵌入层,或者简称为嵌入层,英文为Embedding layer。词嵌入是一类技术,是指单个词在预定义的向量空间中被表示为实数向量,每个单词都映射到一个向量。请参阅图3,图3为本申请实施例提供的文本生成方法中词向量示意图。如图3所示,假如在一个文本中包含“猫”“狗”及“爱情”等若干单词,而这若干单词映射到向量空间中,“猫”对应的向量为(0.1,0.2,0.3),“狗”对应的向量为(0.2,0.2,0.4),“爱情”对应的映射为(-0.4,-0.5,-0.2)(本数据仅为示意)。像这种将文本X{x1,x2,x3,x4,x5……xn}映射到多维向量空间Y{y1,y2,y3,y4,y5……yn},这个映射过程就叫做词嵌入。之所以希望把每个单词都变成一个向量,目的还是为了方便计算,比如“猫”,“狗”,“爱情”三个词。对于我们人而言,可以知道“猫”和“狗”表示的都是动物,而“爱情”是表示的一种情感,但是对于机器而言,这三个词都是用0和1表示成二进制的字符串而已,无法对其进行计算。而通过词嵌入这种方式将单词转变为词向量,机器便可对单词进行计算,通过计算不同词向量之间夹角余弦值cos而得出单词之间的相似性,比如,在图3中,由于cosα<cosβ,可“猫”与“狗”更相似,猫与“爱情”差异较大。
具体地,终端通过文本生成模型中的词嵌入层将初始文本和预设预测词汇分别转化为对应的词向量,也就是将输入的自然语言编码成词向量,在本申请实施例中,是将所述初始文本转化为第一词向量,将所述预设预测词汇转化为第二词向量,为文本生成做准备。具体实施时,可以使用预训练好的词向量,也可以直接在训练文本生成的过程中训练出一套词向量,不过使用预训练好的词向量比在训练文本生成的过程中训练出一套词向量快100倍不止。如果使用预训练好的词向量,又分为Static方法和No-static方法,Static方法是指在训练文本生成过程中不再调节词向量的参数,No-static方法在文本生成模型的训练过程中调节词向量的参数,所以No-static方法的结果比Static方法的结果要好。
进一步地,还可以不在每一个Batch(批)中都调节Embedding层(嵌入层),而是每100个Batch调节一次,这样可以减少训练的时间,又可以微调词向量。
更进一步地,可以使用训练好的预设词向量字典将所述初始文本进行词嵌 入以将所述初始文本转化为词向量。比如,词向量可以采用Word2Vec预训练词向量,即每个词汇都有对应的向量表示,此类向量表示能够以数据形式表达词汇信息,词向量维度可以为300。其中,Word2vec,英文为Word to vector,是一款用于训练词向量的软件工具,用来产生词向量的相关模型,词向量的自动训练可以通过Python中的Gensim库实现。
S230、将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵。
其中,卷积神经网络,英文为Convolutional Neural Networks,简称为CNN,是一类包含卷积或者相关计算且具有深度结构的前馈神经网络(Feedforward Neural Networks),是深度学习(Deep Learning)的代表算法之一。由于卷积神经网络能够进行平移不变分类(英文为Shift-Invariant Classification),因此也被称为“平移不变人工神经网络(英文为Shift-Invariant Artificial Neural Networks,简称为SIANN)。
注意力,又称为注意力机制,或者注意力模型,或者注意力结构,英文为Attention Model。自然语言处理中的注意力模型,借鉴了人类的注意力概念,一般来说,视觉注意力是人类视觉所特有的大脑信号处理机制,人类视觉通过快速扫描全局图像,获得需要重点关注的目标区域,也就是一般所说的注意力焦点,而后对这一区域投入更多注意力资源,以获取更多所需要关注目标的细节信息,而抑制其他无用信息,人类视觉注意力极大地提高了视觉信息处理的效率与准确性,本申请实施例中的注意力从本质上讲和人类的选择性视觉注意力类似,核心目标也是从众多信息中选择出对当前任务目标更关键的信息。
进一步地,注意力模型可以表现为一种函数,比如y=f(x),y=f(x)可以为线性关系,比如,y=wx+b,其中,y表示输出,x表示输入,w和b分别表示x和y线性关系的参数,w和b可以分别在训练过程中得到调整。
注意力矩阵是指权重在矩阵中分配后的矩阵。在卷积神经网络中,卷积层的功能是对输入数据进行特征提取,其内部包含多个卷积核,组成卷积核的每个元素都对应一个权重系数和一个偏差,是以矩阵形式进行卷积,因此经过卷积并且分配权重后生成注意力矩阵。
具体地,请参阅图4,终端接收用户输入的初始文本后,通过词嵌入层将所述初始文本进行词嵌入以获得第一词向量,然后终端通过卷积层中的第一卷积层对所述词向量进行卷积,也就是通过第一卷积神经网络对所述第一词向量进行卷积并经Softmax函数归一化后以得到所述第一词向量的第一词向量概率,同时通过第一卷积层中的第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量,将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵。
类似地、终端接收预设预测词汇后,通过词嵌入层将所述预设预测词汇进行词嵌入以获得第二词向量,然后终端通过卷积层中的第二卷积层对所述第二词向量进行卷积,也就是通过第二卷积神经网络对所述第二词向量进行卷积并经Softmax函数归一化后以得到所述第二词向量的第二词向量概率,同时通过第二卷积层中的第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量,将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
S240、将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵。
其中,矩阵相乘是指矩阵乘法,英文为Matrixmultiplication,指一般矩阵乘积。
具体地,将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵。比如,假若有A和B两矩阵,设A为m×p的矩阵,B为p×n的矩阵,那么称m×n的矩阵C为矩阵A与B的乘积,记作C=AB,其中矩阵C中的第i行第j列元素可以表示为:
Figure PCTCN2019092519-appb-000001
比如,
Figure PCTCN2019092519-appb-000002
S250、将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成 预测文本。
其中,归一化是一种简化计算的方式,即将有量纲的表达式,经过变换,化为无量纲的表达式,成为标量,英文为Normalization。归一化方法有两种形式,一种是把数变为(0,1)之间的小数,一种是把有量纲表达式变为无量纲表达式。主要是为了数据处理方便提出来的,把数据映射到0~1范围之内处理,更加便捷快速。常用的归一化函数包括Softmax函数。其中,Softmax函数,或称归一化指数函数,是逻辑函数的一种推广,它能将一个含任意实数的K维向量z“压缩”到另一个K维实向量σ(z)中,使得每一个元素的范围都在(0,1)之间,并且所有元素的和为1,Softmax函数实际上是有限项离散概率分布的梯度对数归一化。
具体地,将所述第三注意力矩阵经归一化后,获取第三注意力矩阵中各个向量的权重,或者称为各个向量的概率,如图4所示,将所述第三注意力矩阵经Softmax函数归一化后得到第三词向量,然后将第三词向量与预设预测词汇的各个向量进行匹配,从而将第三注意力矩阵中各个向量转化为预设预测词汇中的各个自然语言的词汇以生成预测文本。进一步地,生成预测文本的输出由文本生成模型中的注意力机制完成处理,输出即为所生成的文本内容,信息完成提炼后,文本生成模型通过卷积层、第一注意力层以及第二注意力层组建输出内容,其中,第二注意力层为全连接网络结构,输出函数为Softmax,用于限制注意力范围以实现通过注意力权重调整后的数据将输入卷积层,得到预测对象的词向量,并将词向量与预设预测词汇组成的字典进行匹配,以确定所要输出的预测文本。
更进一步地,文本生成模型中的卷积神经网络构建完毕后,首先要进行文本生成模型的训练,其中,文本生成模型的损失函数为交叉熵,训练方法为ADAM学习率为0.001,其中,ADAM,英文为Adaptive Moment Estimation,是自适应矩估计。同时,在训练神经网络时,需要设置学习率控制参数更新的速度,其中,学习率,英文为Learing rate,又称为学习速率,用于控制模型的学习进度。神经网络的训练通过Python中的Tensorflow库实现。训练完毕的文本生成模型,才可用于用户输入词语预测。
本申请实施例在实现文本生成时,通过获取进行文本生成的初始文本和预设预测词汇,将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量,将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵,将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵,将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本,从而根据输入文本,通过卷积神经网络进行信息提炼,在预设预测词汇范围内生成具有较强关联属性的预测文本,相比于传统技术中的循环神经网络,本申请实施例中由于采取多尺度的卷积神经网络的并行计算特性,建立的文本生成模型具有较高的训练效率。
请参阅图5,如图5所示,在该实施例中,所述将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵的步骤包括:
S510、通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率;
S520、通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量;
S530、将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵;
S540、通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率;
S550、通过所述第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量;
S560、将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
具体地,终端需要首先建立第一卷积神经网络和第二卷积神经网络以实现通过卷积神经网络捕捉所述词向量的信息以得到所述词向量之间的词向量关系。
由于本申请实施例的应用场景是输入文本预测以进行文本生成,因此文本生成模型需要根据用户已经输入的内容,进行下一步的输入预测。由于输入预测可能取决于已输入的一个或多个词,因此文本生成模型设立了多维度的卷积核以捕捉输入文本的局部信息。
请继续参阅图4,该文本生成模型包括第一卷积层和第二卷积层两并行卷积层,也就是第一卷积神经网络所属的卷积层和第二卷积神经网络所属的卷积层,第一卷积层和第二卷积层中每层卷积层又分别包括两部分并行子卷积层,其中,每一卷积层中的一子卷积层通过Softmax函数映射后与另一子卷积层相乘,每一卷积层通过建立两部分子卷积核进行点乘,以实现信息提炼。其中,点乘,也叫向量的内积、数量积,点乘的结果是一个数,比如,向量a·向量b=|a||b|cos<a,b>,cos<a,b>表示向量a和向量b夹角的余弦值,将向量用坐标表示(三维向量),若向量a=(a1,b1,c1),向量b=(a2,b2,c2),则向量a·向量b=a1a2+b1b2+c1c2。另一方面,该文本生成模型已预先设置有预设预测词汇,比如,已建立了1000个词语作为可选预测词语,对该预设预测词语在嵌入层进行词向量转换以转化为第二词向量,并接入第二卷积程中比如高度为1的一维卷积层进行卷积运算输出。
请继续参阅图4,在第一卷积层中,文本生成模型通过词嵌入层实现文本与词向量的转化,并输入第一卷积神经网络所属的第一卷积层,通过第一卷积神经网络对所述第一词向量进行卷积并经Softmax函数归一化后以得到所述第一词向量的第一词向量概率,通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量,将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵。其中,该第一卷积层的高度可以包括有1维度与3维度的卷积神经网络两类,每类卷积神经网络各128通道。第一卷积层中Softmax函数归一化之前的第一卷积神经网络和第一卷积层中获得卷积第一词向量的第一卷积神经网络可以相同也可以不同。若第一卷积层中Softmax函数归一化之前的第一卷积神经网络和第一卷积层中获得卷积第一词向量的第一卷积神经网络相同,第一卷积层中Softmax函数归一化之前的第一卷积神经网络和第一卷积层中获得卷积第一词向量的第一卷积神经网络可以均为1维度的卷积神经网 络或者均为3维度的卷积神经网络。若第一卷积层中Softmax函数归一化之前的第一卷积神经网络和第一卷积层中获得卷积第一词向量的第一卷积神经网络不相同,比如,第一卷积层中Softmax函数归一化之前的第一卷积神经网络为3维度的卷积神经网络,第一卷积层中获得卷积第一词向量的卷积神经网络为1维度的卷积神经网络。
与第一注意力矩阵获得的方式类似,请继续参阅图4,终端接收预设预测词汇后,通过词嵌入层将所述预设预测词汇进行词嵌入以获得第二词向量,然后终端通过卷积层中的第二卷积层对所述第二词向量进行卷积,也就是通过第二卷积神经网络对所述第二词向量进行卷积并经Softmax函数归一化后以得到所述第二词向量的第二词向量概率,同时通过第二卷积层中的第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量,将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
最后,本申请实施例的目标是输入词语预测,由于文本生成模型输入的初始文本具有不定长的特点,该文本生成模型通过不定长训练文本,以及可选的预设预测词语,输出了两部分矩阵,也就是第一注意力矩阵和第二注意力矩阵,并将此两部分矩阵相乘得到第三注意力矩阵,并将第三注意力矩阵进行Softmax函数映射,将第三注意力矩阵中的向量按照概率由高到低的顺序输出概率靠前的词语作为预测词语以生成预测文本,以增大文本输出准确性的概率,提高用户输入的效率。
进一步地,所述通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率的步骤包括:
通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后捕捉所述第一词向量的短期信息与长期信息以得到第一词向量概率;
所述通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率的步骤包括:
通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后捕捉所述第二词向量的短期信息与长期信息以得到第二词向量概率。
具体地,由于文本生成模型设立了多维度的卷积核以捕捉输入文本的局部 信息,所述局部信息是指词向量的信息,词向量的信息是指输入文本中包括的词汇序列之间的关联信息,也可以理解为输入文本的序列信息,用来描述输入文本的语境关系,词汇之间的搭配以形成特定含义。比如,对于上述“猫”和“狗”搭配的概率就比“猫”与“爱情”搭配的几率大,再比如,对于中文中的固定成语就体现了对应的语境关系和序列信息,比如,一提到“千里之行”,一般都会搭配“始于足下”这样的文本内容。
在本申请实施例中,词向量的信息包括短期信息与长期信息,短期信息是指预设数量词汇以下的序列信息,短期信息又可以称为短期序列信息,长期信息是指预设数量及预设数量以上词汇之间的序列信息,长期信息有可以称为长期序列信息。比如,短期信息为1个词或者两个词的词汇所体现的文本中的信息,长期信息为3个词、4个词及4个词的词汇体现的文本中的序列信息。通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后捕捉所述第一词向量的短期信息与长期信息以得到第一词向量概率,通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后捕捉所述第二词向量的短期信息与长期信息以得到第二词向量概率,通过卷积神经网络对短息信息与长期信息的捕捉,可以分别充分获取的初始文本与预设预测词汇各自的内部关联性,从而提高预测文本的准确性。
在一个实施例中,所述将所述第三注意力矩阵经归一化后得到第三词向量的步骤之后,还包括:
按照所述第三词向量的概率由高到低筛选出预设数量的第三词向量;
所述将所述第三词向量与预设预测词汇进行匹配以生成预测文本的步骤包括:
将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本。
具体地,按照预先设置要显示的预测生成文本的数量按照所述第三词向量的概率由高到低筛选出预设数量的第三词向量,然后将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本。比如,预先设置要生成5个预测词汇,按照所述第三词向量的概率由高到低筛选出5个 第三词向量,然后将筛选出的5个第三词向量与预设预测词汇进行匹配以生成5个词汇的预测文本,并将5个预测词汇组成的生成文本进行输出,从而不需要将预测的所有文本全部匹配并输出,减少了数据处理量,提高了文本预测的效率。
在一个实施例中,所述将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本的步骤之后,还包括:
按照预设方式显示所述预设数量的所述预测文本。
具体地,将生成的预测文本按照对应的第三词向量的概率由高到低以横排或者竖排的方式显示,也就是对应所述第三词向量的概率由高到低以横排或者竖排的方式显示所述预设数量的所述预测文本。比如,预先设置要生成5个预测词汇,按照所述第三词向量的概率由高到低筛选出5个第三词向量,然后将筛选出的5个第三词向量与预设预测词汇进行匹配以生成5个词汇的预测文本,并将5个预测词汇组成的生成文本进行输出,将生成的5个词汇的预测文本按照对应的第三词向量的概率由高到低以横排或者竖排的方式显示。
需要说明的是,上述各个实施例所述的文本生成方法,可以根据需要将不同实施例中包含的技术特征重新进行组合,以获取组合后的实施方案,但都在本申请要求的保护范围之内。
请参阅图6,图6为本申请实施例提供的文本生成装置的示意性框图。对应于上述文本生成方法,本申请实施例还提供一种文本生成装置。如图6所示,该文本生成装置包括用于执行上述文本生成方法的单元,该装置可以被配置于终端或者服务器等计算机设备中。具体地,请参阅图6,该文本生成装置600包括获取单元601、转化单元602、卷积单元603、得到单元604及匹配单元605。
其中,获取单元601,用于获取进行文本生成的初始文本和预设预测词汇;
转化单元602,用于将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;
卷积单元603,用于将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;
得到单元604,用于将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;
匹配单元605,用于将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
请参阅图7,图7为本申请实施例提供的文本生成装置的另一个示意性框图。如图7所示,在该实施例中,所述卷积单元603包括:
第一卷积子单元6031,用于通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率;
第二卷积子单元6032,用于通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量;
第一相乘子单元6033,用于将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵;
第三卷积子单元6034,用于通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率;
第四卷积子单元6035,用于通过所述第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量;
第二相乘子单元6036,用于将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
在一个实施例中,所述第一卷积子单元6031,用于通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后捕捉所述第一词向量的短期信息与长期信息以得到第一词向量概率;
第三卷积子单元6034,用于通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后捕捉所述第二词向量的短期信息与长期信息以得到第二词向量概率。
请继续参阅图7,如图7所示,所述匹配单元605包括:
归一化子单元6051,用于将所述第三注意力矩阵经归一化后得到第三词向量;
匹配子单元6053,用于将所述第三词向量与预设预测词汇进行匹配以生成 预测文本。
请继续参阅图7,如图7所示,所述匹配单元605还包括:
筛选子单元6052,用于按照所述第三词向量的概率由高到低筛选出预设数量的第三词向量;
所述匹配子单元6053,用于将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本。
在一个实施例中,所述归一化子单元6051,用于将所述第三注意力矩阵经Softmax函数归一化后得到第三词向量。
请继续参阅图7,如图7所示,所述文本生成装置600还包括:
显示单元606,用于按照预设方式显示所述预设数量的所述预测文本。
需要说明的是,所属领域的技术人员可以清楚地了解到,上述文本生成装置和各单元的具体实现过程,可以参考前述方法实施例中的相应描述,为了描述的方便和简洁,在此不再赘述。
同时,上述文本生成装置中各个单元的划分和连接方式仅用于举例说明,在其他实施例中,可将文本生成装置按照需要划分为不同的单元,也可将文本生成装置中各单元采取不同的连接顺序和方式,以完成上述文本生成装置的全部或部分功能。
上述文本生成装置可以实现为一种计算机程序的形式,该计算机程序可以在如图8所示的计算机设备上运行。
请参阅图8,图8是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备800可以是台式机电脑或者服务器等计算机设备,也可以是其他设备中的组件或者部件。
参阅图8,该计算机设备800包括通过系统总线801连接的处理器802、存储器和网络接口805,其中,存储器可以包括非易失性存储介质803和内存储器804。
该非易失性存储介质803可存储操作系统8031和计算机程序8032。该计算机程序8032被执行时,可使得处理器802执行一种上述文本生成方法。
该处理器802用于提供计算和控制能力,以支撑整个计算机设备800的运 行。
该内存储器804为非易失性存储介质803中的计算机程序8032的运行提供环境,该计算机程序8032被处理器802执行时,可使得处理器802执行一种上述文本生成方法。
该网络接口805用于与其它设备进行网络通信。本领域技术人员可以理解,图8中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备800的限定,具体的计算机设备800可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。例如,在一些实施例中,计算机设备可以仅包括存储器及处理器,在这样的实施例中,存储器及处理器的结构及功能与图8所示实施例一致,在此不再赘述。
其中,所述处理器802用于运行存储在存储器中的计算机程序8032,以实现本申请实施例的文本生成方法。
应当理解,在本申请实施例中,处理器802可以是中央处理单元(Central Processing Unit,CPU),该处理器802还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
本领域普通技术人员可以理解的是实现上述实施例的方法中的全部或部分流程,是可以通过计算机程序来完成,该计算机程序可存储于一计算机可读存储介质。该计算机程序被该计算机系统中的至少一个处理器执行,以实现上述文本生成方法的实施例的步骤。
因此,本申请实施例还提供一种计算机可读存储介质。该计算机可读存储介质存储有计算机程序,该计算机程序被处理器执行时使处理器执行以上各实施例中所描述的文本生成方法的步骤。
所述计算机可读存储介质可以是U盘、移动硬盘、只读存储器(Read-Only  Memory,ROM)、磁碟或者光盘等各种可以存储计算机程序的计算机可读存储介质。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
以上所述,仅为本申请的具体实施方式,但本申请明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。

Claims (20)

  1. 一种文本生成方法,包括:
    获取进行文本生成的初始文本和预设预测词汇;
    将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;
    将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;
    将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;
    将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
  2. 根据权利要求1所述文本生成方法,其中,所述将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵的步骤包括:
    通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率;
    通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量;
    将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵;
    通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率;
    通过所述第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量;
    将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
  3. 根据权利要求2所述文本生成方法,其中,所述通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率的步骤包括:
    通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后捕捉所述第一词向量的短期信息与长期信息以得到第一词向量概率;
    所述通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率的步骤包括:
    通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后捕捉所述第二词向量的短期信息与长期信息以得到第二词向量概率。
  4. 根据权利要求1所述文本生成方法,其中,所述将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本的步骤包括:
    将所述第三注意力矩阵经归一化后得到第三词向量;
    将所述第三词向量与预设预测词汇进行匹配以生成预测文本。
  5. 根据权利要求4所述文本生成方法,其中,所述将所述第三注意力矩阵经归一化后得到第三词向量的步骤之后,还包括:
    按照所述第三词向量的概率由高到低筛选出预设数量的第三词向量;
    所述将所述第三词向量与预设预测词汇进行匹配以生成预测文本的步骤包括:
    将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本。
  6. 根据权利要求4所述文本生成方法,其中,所述将所述第三注意力矩阵经归一化后得到第三词向量的步骤包括:
    将所述第三注意力矩阵经Softmax函数归一化后得到第三词向量。
  7. 根据权利要求5所述文本生成方法,其中,所述将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本的步骤之后,还包括:
    按照预设方式显示所述预设数量的所述预测文本。
  8. 根据权利要求7所述文本生成方法,其中,所述按照预设方式显示所述预设数量的所述预测文本的步骤包括:
    对应所述第三词向量的概率由高到低以横排或者竖排的方式显示所述预设数量的所述预测文本。
  9. 一种文本生成装置,包括:
    获取单元,用于获取进行文本生成的初始文本和预设预测词汇;
    转化单元,用于将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;
    卷积单元,用于将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;
    得到单元,用于将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;
    匹配单元,用于将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
  10. 根据权利要求9所述文本生成装置,其中,所述卷积单元包括:
    第一卷积子单元,用于通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率;
    第二卷积子单元,用于通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量;
    第一相乘子单元,用于将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵;
    第三卷积子单元,用于通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率;
    第四卷积子单元,用于通过所述第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量;
    第二相乘子单元,用于将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
  11. 一种计算机设备,其特征在于,所述计算机设备包括存储器以及与所述存储器相连的处理器;所述存储器用于存储计算机程序;所述处理器用于运行所述存储器中存储的计算机程序,以执行如下步骤:
    获取进行文本生成的初始文本和预设预测词汇;
    将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;
    将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;
    将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;
    将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
  12. 根据权利要求11所述计算机设备,其中,所述将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵的步骤包括:
    通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率;
    通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量;
    将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵;
    通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率;
    通过所述第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量;
    将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
  13. 根据权利要求12所述计算机设备,其中,所述通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率的步骤包括:
    通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后捕捉所述第一词向量的短期信息与长期信息以得到第一词向量概率;
    所述通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率的步骤包括:
    通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后捕捉所述第二词向量的短期信息与长期信息以得到第二词向量概率。
  14. 根据权利要求11所述计算机设备,其中,所述将所述第三注意力矩阵 经归一化后与预设预测词汇进行匹配以生成预测文本的步骤包括:
    将所述第三注意力矩阵经归一化后得到第三词向量;
    将所述第三词向量与预设预测词汇进行匹配以生成预测文本。
  15. 根据权利要求14所述计算机设备,其中,所述将所述第三注意力矩阵经归一化后得到第三词向量的步骤之后,还包括:
    按照所述第三词向量的概率由高到低筛选出预设数量的第三词向量;
    所述将所述第三词向量与预设预测词汇进行匹配以生成预测文本的步骤包括:
    将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本。
  16. 根据权利要求14所述计算机设备,其中,所述将所述第三注意力矩阵经归一化后得到第三词向量的步骤包括:
    将所述第三注意力矩阵经Softmax函数归一化后得到第三词向量。
  17. 根据权利要求15所述计算机设备,其中,所述将筛选出的所述预设数量的第三词向量与预设预测词汇进行匹配以生成预设数量的预测文本的步骤之后,还包括:
    按照预设方式显示所述预设数量的所述预测文本。
  18. 根据权利要求17所述计算机设备,其中,所述按照预设方式显示所述预设数量的所述预测文本的步骤包括:
    对应所述第三词向量的概率由高到低以横排或者竖排的方式显示所述预设数量的所述预测文本。
  19. 一种计算机可读存储介质,其中,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行以下步骤:
    获取进行文本生成的初始文本和预设预测词汇;
    将所述初始文本和所述预设预测词汇分别进行词嵌入以将所述初始文本转化为第一词向量和将所述预设预测词汇转化为第二词向量;
    将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵;
    将所述第一注意力矩阵和所述第二注意力矩阵相乘以得到第三注意力矩阵;
    将所述第三注意力矩阵经归一化后与预设预测词汇进行匹配以生成预测文本。
  20. 根据权利要求19所述计算机可读存储介质,其中,所述将所述第一词向量和所述第二词向量分别通过对应的卷积神经网络获得所述第一词向量的第一注意力矩阵和所述第二词向量的第二注意力矩阵的步骤包括:
    通过第一卷积神经网络对所述第一词向量进行卷积并经归一化后得到所述第一词向量的第一词向量概率;
    通过所述第一卷积神经网络对所述第一词向量进行卷积以得到卷积第一词向量;
    将所述第一词向量概率和所述卷积第一词向量相乘以得到第一注意力矩阵;
    通过第二卷积神经网络对所述第二词向量进行卷积并经归一化后得到所述第二词向量的第二词向量概率;
    通过所述第二卷积神经网络对所述第二词向量进行卷积以得到卷积第二词向量;
    将所述第二词向量概率和所述卷积第二词向量相乘以得到第二注意力矩阵。
PCT/CN2019/092519 2019-01-23 2019-06-24 文本生成方法、装置、计算机设备及存储介质 Ceased WO2020151175A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910064116.4A CN109918630B (zh) 2019-01-23 2019-01-23 文本生成方法、装置、计算机设备及存储介质
CN201910064116.4 2019-01-23

Publications (1)

Publication Number Publication Date
WO2020151175A1 true WO2020151175A1 (zh) 2020-07-30

Family

ID=66960501

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/092519 Ceased WO2020151175A1 (zh) 2019-01-23 2019-06-24 文本生成方法、装置、计算机设备及存储介质

Country Status (2)

Country Link
CN (1) CN109918630B (zh)
WO (1) WO2020151175A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112183057A (zh) * 2020-09-16 2021-01-05 北京思源智通科技有限责任公司 文章生成方法、装置、智能设备和存储介质
CN112561474A (zh) * 2020-12-14 2021-03-26 华南理工大学 一种基于多源数据融合的智能人格特性评价方法
CN113761949A (zh) * 2021-04-23 2021-12-07 腾讯科技(深圳)有限公司 一种文本翻译的方法、相关装置及存储介质
CN115115877A (zh) * 2022-06-22 2022-09-27 桂林电子科技大学 一种基于多注意力机制的卷积神经网络隐写分析方法

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109918630B (zh) * 2019-01-23 2023-08-04 平安科技(深圳)有限公司 文本生成方法、装置、计算机设备及存储介质
CN110427456A (zh) * 2019-06-26 2019-11-08 平安科技(深圳)有限公司 一种词语联想的方法及装置
CN110442767B (zh) * 2019-07-31 2023-08-18 腾讯科技(深圳)有限公司 一种确定内容互动平台标签的方法、装置及可读存储介质
CN111061867B (zh) * 2019-10-29 2022-10-25 平安科技(深圳)有限公司 基于质量感知的文本生成方法、设备、存储介质及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180293499A1 (en) * 2017-04-11 2018-10-11 Sap Se Unsupervised neural attention model for aspect extraction
CN108829719A (zh) * 2018-05-07 2018-11-16 中国科学院合肥物质科学研究院 一种非事实类问答答案选择方法及系统
CN108845990A (zh) * 2018-06-12 2018-11-20 北京慧闻科技发展有限公司 基于双向注意力机制的答案选择方法、装置和电子设备
CN109918630A (zh) * 2019-01-23 2019-06-21 平安科技(深圳)有限公司 文本生成方法、装置、计算机设备及存储介质

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9317482B2 (en) * 2012-10-14 2016-04-19 Microsoft Technology Licensing, Llc Universal FPGA/ASIC matrix-vector multiplication architecture
CN108664632B (zh) * 2018-05-15 2021-09-21 华南理工大学 一种基于卷积神经网络和注意力机制的文本情感分类算法
CN109034378B (zh) * 2018-09-04 2023-03-31 腾讯科技(深圳)有限公司 神经网络的网络表示生成方法、装置、存储介质和设备
CN109241536B (zh) * 2018-09-21 2020-11-06 浙江大学 一种基于深度学习自注意力机制的句子排序方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180293499A1 (en) * 2017-04-11 2018-10-11 Sap Se Unsupervised neural attention model for aspect extraction
CN108829719A (zh) * 2018-05-07 2018-11-16 中国科学院合肥物质科学研究院 一种非事实类问答答案选择方法及系统
CN108845990A (zh) * 2018-06-12 2018-11-20 北京慧闻科技发展有限公司 基于双向注意力机制的答案选择方法、装置和电子设备
CN109918630A (zh) * 2019-01-23 2019-06-21 平安科技(深圳)有限公司 文本生成方法、装置、计算机设备及存储介质

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112183057A (zh) * 2020-09-16 2021-01-05 北京思源智通科技有限责任公司 文章生成方法、装置、智能设备和存储介质
CN112561474A (zh) * 2020-12-14 2021-03-26 华南理工大学 一种基于多源数据融合的智能人格特性评价方法
CN112561474B (zh) * 2020-12-14 2024-04-30 华南理工大学 一种基于多源数据融合的智能人格特性评价方法
CN113761949A (zh) * 2021-04-23 2021-12-07 腾讯科技(深圳)有限公司 一种文本翻译的方法、相关装置及存储介质
CN115115877A (zh) * 2022-06-22 2022-09-27 桂林电子科技大学 一种基于多注意力机制的卷积神经网络隐写分析方法

Also Published As

Publication number Publication date
CN109918630B (zh) 2023-08-04
CN109918630A (zh) 2019-06-21

Similar Documents

Publication Publication Date Title
WO2020151175A1 (zh) 文本生成方法、装置、计算机设备及存储介质
US20230162723A1 (en) Text data processing method and apparatus
CN109299344B (zh) 排序模型的生成方法、搜索结果的排序方法、装置及设备
CN107836000B (zh) 用于语言建模和预测的改进的人工神经网络方法、电子设备
CN113656563B (zh) 一种神经网络搜索方法及相关设备
WO2020140403A1 (zh) 文本分类方法、装置、计算机设备及存储介质
US12393840B2 (en) Granular neural network architecture search over low-level primitives
WO2022001724A1 (zh) 一种数据处理方法及装置
US20210390370A1 (en) Data processing method and apparatus, storage medium and electronic device
CN112529149B (zh) 一种数据处理方法及相关装置
CN114840734B (zh) 多模态表示模型的训练方法、跨模态检索方法及装置
WO2020140632A1 (zh) 隐含特征提取方法、装置、计算机设备及存储介质
CN114782722B (zh) 图文相似度的确定方法、装置及电子设备
CN110968725B (zh) 图像内容描述信息生成方法、电子设备及存储介质
WO2025241750A1 (zh) 基于大模型的问答方法、装置、设备及存储介质
US20250284880A1 (en) Summary Generation Method and Related Device Thereof
CN114841161A (zh) 事件要素抽取方法、装置、设备、存储介质和程序产品
CN116312489A (zh) 一种模型训练方法及其相关设备
CN116796038A (zh) 遥感数据检索方法、装置、边缘处理设备及存储介质
CN117035019A (zh) 一种数据处理方法及相关设备
WO2024253871A1 (en) Computer memory access for machine learning models
WO2020143303A1 (zh) 深度学习模型训练方法、装置、计算机设备及存储介质
CN118262380A (zh) 一种模型训练方法及其相关设备
CN117765341A (zh) 一种数据处理方法及相关装置
US20240386274A1 (en) Data Processing Method and Related Device

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 18.11.2021).

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

Ref document number: 19911911

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 19911911

Country of ref document: EP

Kind code of ref document: A1