A method, device, equipment and storage medium for generating similar command text

By processing the command data set and generating similar sentence pairs, the text generation model is trained, which solves the problem of insufficient robustness of intent recognition caused by the discrete data set in the existing technology, and realizes the automatic generation of similar command text and the grammatical form. Diversity enhances the stability of intent recognition.

CN114936548BActive Publication Date: 2024-09-06BEIJING INTENGINE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210304836.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-22
Publication Date
2024-09-06
Estimated Expiration
2042-03-22

AI Technical Summary

Technical Problem

The manually obtained data sets in the existing technology have data discreteness and cannot fully obtain expressions in various grammatical forms, resulting in insufficient robustness of intent recognition.

Method used

By obtaining command data sets for corpus processing, syntactic templates and similar sentence pairs are generated, and these templates are used to train the preset text generation model to generate similar text generation models, and then generate similar command texts covering various grammatical expressions.

Benefits of technology

It realizes the automatic generation of similar command texts, enhances the robustness of intent recognition and the diversity of grammatical forms, and ensures the controllability of the output syntactic form.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114936548B
    Figure CN114936548B
Patent Text Reader

Abstract

The present invention discloses a method, device, equipment and storage medium for generating similar command texts, the method comprising: obtaining a command data set, performing corpus processing on the command data set, generating a syntactic template and similar sentence pairs; training a preset text generation model based on the syntactic template and the similar sentence pairs, generating a similar text generation model; inputting the command data set and the syntactic template into the above-mentioned text generation model, generating similar command texts. The method realizes the automatic generation of similar command texts, effectively expands the command data set, and fully covers various grammatical expressions of device commands.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a method, device, equipment and storage medium for generating similar command texts. Background Art

[0002] At present, voice control is used for household devices such as lighting, air conditioning, television, curtains, etc. Most of them are based on a fixed device command vocabulary. The user reads out the command words contained in the device command vocabulary, and the intention recognition algorithm recognizes the intention and executes the command. If the user's command expression exceeds the scope of the vocabulary, the intention recognition algorithm cannot recognize the command intention and cannot execute the command. For example, there is a command "turn on the air conditioner" in the vocabulary. The user can turn on the air conditioner by saying "turn on the air conditioner", but it cannot be turned on by saying "turn on the air conditioner".

[0003] In order to avoid requiring users to memorize command vocabularies and use more flexible and diverse command expressions, the intent recognition algorithm needs to learn enough device command data sets with the same semantics but different expressions. Currently, device command data sets are mainly obtained through manual collection, but the cost of manual acquisition of data sets is very high, and the data obtained is relatively discrete, and it is not possible to fully obtain expressions in various grammatical forms, which leads to insufficient robustness of intent recognition.

[0004] Therefore, how to effectively augment the existing data sets and obtain the same semantic command expressions covering various grammatical patterns is an urgent problem to be solved by technical personnel in this field. Summary of the invention

[0005] Therefore, the technical problem to be solved by the present invention is to overcome the data discreteness of the manually acquired data set in the prior art, which cannot fully acquire expressions in various grammatical forms, resulting in insufficient robustness of intent recognition, thereby providing a method, device, equipment and storage medium for generating similar command texts.

[0006] The embodiment of the present invention provides a method for generating similar command texts, comprising the following steps:

[0007] Acquire a command data set, perform corpus processing on the command data set, and generate syntactic templates and similar sentence pairs;

[0008] Training a preset text generation model based on the syntactic template and the similar sentence pairs to generate a similar text generation model;

[0009] The command data set and the syntactic template are input into the text generation model to generate similar command texts.

[0010] Optionally, the acquiring of a command data set, performing corpus processing on the command data set, and generating a syntactic template and similar sentence pairs includes:

[0011] Extracting command sentences from the command data set, performing lexical analysis on the command sentences using a lexical analyzer, and generating part-of-speech features;

[0012] Sorting the part-of-speech features to generate the syntactic template;

[0013] Command sentences are extracted from the command data set, and the command sentences with the same command type are paired up to generate the similar sentence pairs.

[0014] Optionally, the step of inputting the command data set and the syntactic template into the text generation model to generate similar command texts includes:

[0015] Acquire a source sentence based on the command data set, perform semantic encoding on the source sentence, and generate a source sentence semantic latent vector;

[0016] Acquire the syntactic template, perform syntactic encoding on the syntactic template, and generate a syntactic latent vector;

[0017] Concatenating the semantic latent vector with the syntactic latent vector to generate a concatenated vector;

[0018] The concatenated vector is decoded to generate the similar command text.

[0019] Optionally, the acquiring the syntactic template, performing syntactic encoding on the syntactic template, and generating a syntactic latent vector includes:

[0020] Encoding the part-of-speech feature corresponding to the syntactic template to generate a part-of-speech feature vector;

[0021] Position encoding is performed on the part-of-speech feature vector to generate the syntactic latent vector.

[0022] Optionally, the acquiring the syntactic template, performing syntactic encoding on the syntactic template, and generating a syntactic latent vector includes:

[0023] The syntactic templates corresponding to the command data set are traversed, and the syntactic templates are syntactically encoded in sequence to generate the syntactic latent vectors.

[0024] In a second aspect of the present application, a device for generating similar command text is also proposed, comprising:

[0025] A processing module, used for acquiring a command data set, performing corpus processing on the command data set, and generating a syntactic template and similar sentence pairs;

[0026] A training module, used for training a preset text generation model based on the syntactic template and the similar sentence pairs to generate a similar text generation model;

[0027] A generation module is used to input the command data set and the syntactic template into the above-mentioned text generation model to generate similar command text.

[0028] Optionally, the processing module includes:

[0029] An analysis submodule, used for extracting command sentences from the command data set, performing lexical analysis on the command sentences using a lexical analyzer, and generating part-of-speech features;

[0030] A sorting submodule, used to sort the part-of-speech features and generate the syntactic template;

[0031] The pairing submodule is used to extract command sentences from the command data set, and pair the command sentences with the same command type in pairs to generate similar sentence pairs.

[0032] Optionally, the generating module includes:

[0033] A first encoding submodule, configured to obtain a source sentence based on the command data set, perform semantic encoding on the source sentence, and generate a semantic latent vector of the source sentence;

[0034] A second encoding submodule is used to obtain the syntactic template, perform syntactic encoding on the syntactic template, and generate a syntactic latent vector;

[0035] A concatenation submodule, used for concatenating the semantic latent vector with the syntactic latent vector to generate a concatenated vector;

[0036] The decoding submodule is used to decode the splicing vector to generate the similar command text.

[0037] Optionally, the second encoding submodule includes:

[0038] A first generating unit, configured to encode the part-of-speech feature corresponding to the syntactic template to generate a part-of-speech feature vector;

[0039] The second generating unit is used to perform position encoding on the part-of-speech feature vector to generate the syntactic latent vector.

[0040] Optionally, the acquiring the syntactic template, performing syntactic encoding on the syntactic template, and generating a syntactic latent vector further includes:

[0041] The syntactic templates corresponding to the command data set are traversed, and the syntactic templates are syntactically encoded in sequence to generate the syntactic latent vectors.

[0042] In the third aspect of the present application, a computer device is also proposed, including a processor and a memory, wherein the memory is used to store a computer program, the computer program includes a program, and the processor is configured to call the computer program to execute the method of the first aspect above.

[0043] In a fourth aspect of the present application, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, and the computer program is executed by a processor to implement the method of the first aspect above.

[0044] The technical solution of the present invention has the following advantages:

[0045] 1. The present invention provides a method for generating similar command texts, which processes the corpus of an artificially collected command data set to generate syntactic templates and similar sentence pairs, uses the syntactic templates and similar sentence pairs to train a preset text generation model, generates a trained similar text generation model, takes the command sentences and syntactic templates in the command data set as input, adopts the similar text generation model, and generates the generated similar command text as the final augmented result, thereby realizing the automatic generation of similar command texts, effectively augmenting the command data set, and fully covering various grammatical expressions of device commands.

[0046] 2. The present invention constructs syntactic templates through part-of-speech features, thereby ensuring the diversity of generative grammar forms.

[0047] 3. The similar text generation model in the present invention generates similar command texts by guiding the input of syntactic template encoding, thereby ensuring the controllability of the output syntactic form.

[0048] 4. The present invention cancels the position coding of the source sentence in the input command data set, and performs position coding on the syntactic template, thereby ensuring that the semantic coding is independent of the syntax and enhancing the robustness of the intent recognition of the command data set. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0050] Figure 1 This is a flow chart of a method for generating similar command texts in Embodiment 1 of the present invention;

[0051] Figure 2 A schematic diagram of a method for generating similar command texts in Embodiment 1 of the present invention;

[0052] Figure 3 A schematic diagram of training a text generation model in Example 1 of the present invention;

[0053] Figure 4 A schematic diagram of the structure of a preset text generation model in Embodiment 1 of the present invention;

[0054] Figure 5 Schematic diagram of a syntax encoder in Embodiment 1 of the present invention;

[0055] Figure 6 is a schematic diagram of a semantic encoder in Embodiment 1 of the present invention;

[0056] Figure 7 This is a schematic diagram of a decoder in Embodiment 1 of the present invention;

[0057] Figure 8 This is a flowchart of step S101 in Example 1 of the present invention;

[0058] Fig. 9 This is a schematic diagram of performing corpus processing on a command data set in Example 1 of the present invention;

[0059] Fig.10 A schematic diagram of generating a syntactic template using a lexical analyzer in Embodiment 1 of the present invention;

[0060] Fig.11 A schematic diagram of generating similar sentence pairs using a similar sentence pair generator in Embodiment 1 of the present invention;

[0061] Fig.12 This is a flowchart of step S103 in Example 1 of the present invention;

[0062] Fig.13 A schematic diagram of generating similar command texts by using a decoder in Embodiment 1 of the present invention;

[0063] Fig.14 This is a flowchart of step S1032 in Example 1 of the present invention;

[0064] Fig.15 It is a principle block diagram of a device for generating similar command text in Embodiment 2 of the present invention;

[0065] Fig.16 is a principle block diagram of a specific example of the processing module 151 in Embodiment 2 of the present invention;

[0066] Fig.17 is a principle block diagram of the generating module 153 in Embodiment 2 of the present invention;

[0067] Fig.18 This is a principle block diagram of the second encoding submodule 1532 in Embodiment 2 of the present invention. DETAILED DESCRIPTION

[0068] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0069] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0070] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0071] Example 1

[0072] This embodiment provides a method for generating similar command texts, such as Figure 1-2 As shown, the following steps are included:

[0073] S101, obtaining a command data set, performing corpus processing on the command data set, and generating a syntactic template and similar sentence pairs.

[0074] Among them, a syntactic template library is generated based on the above syntactic templates corresponding to the above command dataset, and the syntactic template library covers various forms of grammar; a similar command pair dataset is generated based on all similar sentence pairs corresponding to the command dataset, and similar sentence pairs refer to sentences with the same semantics (referring to sentences with similar semantics and meanings). Figure 1 For example, a similar sentence pair example of “turn on the air conditioner” is “turn on the air conditioner - turn on the air conditioner”.

[0075] S102: training a preset text generation model based on the syntactic template and the similar sentence pairs to generate a similar text generation model.

[0076] Specifically, similar sentence pairs are used as input data of a preset text generation model, and similar sentence pairs in the above similar sentence pairs are respectively set as source sentences and target sentences, where the source sentence is a sentence input by the preset text generation model, and the target sentence is a sentence expected to be generated by the preset text generation model;

[0077] Furthermore, if Figure 3 As shown in the figure, the training process of training the preset text generation model based on the above syntactic template and the above similar sentence pairs is as follows: syntactically encode the syntactic template of the target sentence to generate a latent vector representation of the syntactic template of the target sentence; semantically encode the text of the source sentence to generate a latent vector representation of the semantics of the source sentence; concatenate the latent vector representation of the syntactic template of the target sentence and the latent vector representation of the semantics of the source sentence, and send them together with the text of the target sentence into the decoder for decoding to obtain a predicted target sentence; calculate the reconstruction loss, that is, the negative log likelihood loss, with the prediction result and the target sentence as input, calculate the reconstruction loss, and then back-propagate to update the model parameters to complete the model training.

[0078] Among them, assuming that the prediction result is y m , the target sentence is y n , m=(1,2,...i), n=(1,2,...i), then the reconstruction loss L mn The calculation formula is as follows:

[0079]

[0080] S103: Input the command data set and the syntactic template into the text generation model to generate similar command text.

[0081] Among them, Figure 4 As shown in the figure, the preset text generation model consists of a syntactic encoder, a semantic encoder and a decoder; the main structure adopts Transformer (Transformer is a classic model of NLP (nature language processing) proposed in June 2017, the encoder of Transformer has 6 layers and the decoder has 6 layers); among them, Figure 5 As shown in the figure, the syntactic encoder is composed of a transformer encoder (an encoder is composed of a neural network and can encode the input text content to form a vector representation of the input text content, also called a hidden vector). The input is the part-of-speech feature in the syntactic template. The embedding (part-of-speech feature encoding) encodes each part-of-speech feature, and then performs position encoding, which is then passed into the encoder to generate a syntactic hidden vector representation. Figure 6 As shown in , the semantic encoder is composed of a transformer encoder. The input is each word in the sentence. Embedding encodes each word and then passes it to the encoder to generate a semantic latent vector representation of the sentence. Figure 7As shown in the figure, the decoder is composed of a transformer decoder (a decoder is a module composed of a neural network, which decodes the output of the encoder and the text input to generate text). The input starts with the start mark of the target sentence, and then the predicted words are added in a loop as input. First, each target word is encoded by embedding, and then position encoding is performed. The generated latent vector representation is passed to the decoder; in the decoder, the latent vector representation of the target word is calculated with the output syntactic latent vector representation and semantic latent vector representation of the encoder for attention calculation (Attention). The attention calculation result is used to generate a vocabulary representation of the target word through dense (representing the fully connected layer in the neural network), thereby generating a similar command text.

[0082] The attention between the decoder and the encoder mentioned above is the interactive attention. The input of this interactive attention is the output of the encoder and the output of the decoder's self-attention. The encoder's self-attention (self-attention mechanism) is the key vector (key) and the value vector (value), and the decoder's self-attention is the query vector (query). The calculation formula using attention is as follows:

[0083]

[0084] In the above formula, Q represents the query vector, K represents the key vector, V represents the value vector, and d k Represents the dimension of the key vector K.

[0085] The above-mentioned method for generating similar command texts performs corpus processing on an artificially collected command data set to generate syntactic templates and similar sentence pairs, uses the syntactic templates and similar sentence pairs to train a preset text generation model, generates a trained similar text generation model, takes the command sentences and syntactic template library in the command data set as input, uses the similar text generation model, and generates the generated similar command text as the final augmented result, thereby realizing the automatic generation of similar command texts, effectively augmenting the command data set, and fully covering various grammatical expressions of device commands.

[0086] Preferably, if Figure 8-9 As shown, in step S101, a command data set is obtained, corpus processing is performed on the command data set, and a syntactic template and similar sentence pairs are generated, including:

[0087] S1011, extracting command sentences from the command data set, performing lexical analysis on the command sentences using a lexical analyzer, and generating part-of-speech features.

[0088] Specifically, a lexical analyzer is pre-trained using a corpus annotated by CTB (Chinese Treebank, a Chinese part-of-speech tagging dataset), and the lexical analyzer is used to automatically perform lexical analysis on the manually collected command dataset, and the lexical analysis result of each sentence is a part-of-speech feature.

[0089] Furthermore, if Fig.10 As shown in the figure, the lexical analyzer is mainly composed of the encoder part of the transformer. The input is a sentence, which is embedded in Chinese characters and then positionally encoded. After passing through several layers of transformers, a latent vector is formed. The latent vector is mapped to the part-of-speech feature through the fully connected layer, thereby completing the part-of-speech feature labeling of each character. The ordered string formed by merging the same part-of-speech features becomes a sentence template.

[0090] S1012. Sort the above-mentioned part-of-speech features to generate the above-mentioned syntactic template.

[0091] Among them, the string formed by the sequence of multiple part-of-speech features is used as a syntactic template (representing the shallow syntax of the sentence), and the syntactic templates corresponding to the command sentences under all command types form a syntactic template library, wherein the string formed by the sequence of multiple part-of-speech features is used as a syntactic template as shown in Table 1 below:

[0092] Table 1

[0093] Command Type Imperative Sentences Syntax Templates Turn on the air conditioner The air conditioner is on (NN, VV, SP) Turn on the air conditioner Please turn on the air conditioner for me (VV, PN, VV, NN) Turn on the air conditioner Please turn on the air conditioner for me. (P, PN, VV, AD, NN, SP) Turn off the air conditioner Turn off the air conditioner (VV, NN) Turn off the air conditioner Turn off the air conditioner (NN, VV, SP) Turn off the air conditioner Turn off the air conditioner. (BN, NN, VV, SP)

[0094] S1013. Extract command sentences from the command data set, and pair the command sentences with the same command type (such as turn on, turn off, set, adjust, query, etc., which are generally named using a typical device command, such as "turn on the air conditioner", "turn off the air conditioner") in pairs to generate the similar sentence pairs.

[0095] Specifically, Fig.11 As shown, the manually collected command data set is processed to generate a sentence set (i.e., command sentence set), and the sentence set is input into a similar sentence pair generator. The similar sentence pair generator determines whether the sentences are similar based on whether the command type of each sentence is the same, and pairs the sentences under the same command type. The output result is similar sentence pairs, forming a similar sentence pair data set.

[0096] Among them, taking the command types and command sentences in Table 1 as an example, a similar sentence pair generator is used to generate a similar sentence pair dataset, and the syntactic annotation of the similar sentence pair dataset is shown in Table 2 below:

[0097] Table 2

[0098]

[0099] Preferably, if Figure 12-13 As shown, in step S103, the command data set and the syntactic template are input into the text generation model to generate similar command texts, including:

[0100] S1031. Obtain a source sentence based on the command data set, perform semantic encoding on the source sentence, and generate a semantic latent vector of the source sentence.

[0101] S1032: Obtain the above syntactic template, perform syntactic encoding on the above syntactic template, and generate a syntactic latent vector.

[0102] Specifically, the syntactic templates corresponding to the command data set are traversed, and the syntactic templates are syntactically encoded in turn to generate the syntactic latent vectors.

[0103] S1033: Concatenate the semantic latent vector with the syntactic latent vector to generate a concatenated vector.

[0104] S1034. Decode the concatenated vector to generate the similar command text.

[0105] Among them, the above semantic latent vector is concatenated with the above syntactic latent vector, and <bos>(Decoder training and decoding auxiliary text symbols, indicating the beginning of the sentence) are decoded together, and the decoder loop predicts each word of the target sentence until it generates <eos>(Decoder training and decoding auxiliary text symbols, indicating the end of the sentence), completing the generation of a target sentence.

[0106] Furthermore, all command sentences in the command data set are traversed, and similar command texts are generated based on all syntactic templates in the syntactic template library as the final augmented result.

[0107] In the prior art, the above-mentioned syntactic template adopts an unsupervised method based on VAE (variational autoencoder model, a neural network model that can realize unsupervised text generation), or directly adopts a transformer model to generate, but there are the following disadvantages: insufficient diversity, the generated sentences are not much different from the input sentences in grammatical structure, and many only replace part of the words; insufficient controllability, many of the generated sentence grammars are unknown, and it cannot be guaranteed to cover the required grammatical types. In view of the above problems, the present invention generates sentences based on syntactic templates to ensure the diversity of generated sentences, guides the generation of similar sentences by inputting the target syntactic template, and ensures the controllability of the output syntactic form.

[0108] Preferably, if Fig.14 As shown, in step S1032, the above syntactic template is syntactically encoded to generate a syntactic latent vector, including:

[0109] S10321. Encode the above-mentioned part-of-speech features corresponding to the above-mentioned syntactic template to generate a part-of-speech feature vector.

[0110] S10322. Positionally encode the above-mentioned part-of-speech feature vector to generate the above-mentioned syntactic latent vector.

[0111] Among them, position coding is not performed in semantic coding because position coding reflects some syntactic information. The semantic coding here hopes to reduce grammatical factors, so position coding is removed.

[0112] In the above encoding process, the syntactic template is positionally encoded, and the source sentence in the input command dataset is positionally encoded, which ensures that the semantic encoding is independent of the syntax and enhances the robustness of the intent recognition of the command dataset.

[0113] Example 2

[0114] This embodiment provides a device for generating similar command texts, such as Fig.15 As shown, including:

[0115] The processing module 151 is used to obtain a command data set, perform corpus processing on the command data set, and generate a syntactic template and similar sentence pairs.

[0116] Among them, a syntactic template library is generated based on the above syntactic templates corresponding to the above command dataset, and the syntactic template library covers various forms of grammar; a similar command pair dataset is generated based on all similar sentence pairs corresponding to the command dataset, and similar sentence pairs refer to sentences with the same semantics (referring to sentences with similar semantics and meanings). Figure 1 For example, a similar sentence pair example of "turn on the air conditioner" is "turn on the air conditioner - turn on the air conditioner".

[0117] The training module 152 is used to train a preset text generation model based on the above syntactic template and the above similar sentence pairs to generate a similar text generation model.

[0118] Specifically, similar sentence pairs are used as input data of a preset text generation model, and similar sentence pairs in the above similar sentence pairs are respectively set as source sentences and target sentences, where the source sentence is a sentence input by the preset text generation model, and the target sentence is a sentence expected to be generated by the preset text generation model;

[0119] Furthermore, the training process of training the preset text generation model based on the above-mentioned syntactic template and the above-mentioned similar sentence pairs is as follows: syntactically encode the syntactic template of the target sentence to generate a latent vector representation of the syntactic template of the target sentence; semantically encode the text of the source sentence to generate a latent vector representation of the semantics of the source sentence; concatenate the latent vector representation of the syntactic template of the target sentence and the latent vector representation of the semantics of the source sentence, and send them together with the text of the target sentence into the decoder for decoding to obtain a predicted target sentence; calculate the reconstruction loss, that is, the negative log likelihood loss, take the prediction result and the target sentence as input, calculate the reconstruction loss, and then back-propagate to update the model parameters to complete the model training.

[0120] Among them, assuming that the prediction result is y m , the target sentence is y n , m=(1,2,...i), n=(1,2,...i), then the reconstruction loss L mn The calculation formula is as follows:

[0121]

[0122] The generation module 153 is used to input the command data set and the syntax template into the text generation model to generate similar command text.

[0123] The preset text generation model consists of a syntactic encoder, a semantic encoder and a decoder; the main structure adopts Transformer (Transformer is a classic model of NLP (nature language processing) proposed in June 2017, with a 6-layer encoder and a 6-layer decoder); Figure 5 As shown in the figure, the syntactic encoder is composed of a transformer encoder (an encoder is composed of a neural network and can encode the input text content to form a vector representation of the input text content, also called a hidden vector). The input is the part-of-speech feature in the syntactic template. The embedding (part-of-speech feature encoding) encodes each part-of-speech feature, and then performs position encoding, which is then passed into the encoder to generate a syntactic hidden vector representation. Figure 6 As shown in , the semantic encoder is composed of a transformer encoder. The input is each word in the sentence. Embedding encodes each word and then passes it to the encoder to generate a semantic latent vector representation of the sentence. Figure 7 As shown in the figure, the decoder is composed of a transformer decoder (a decoder is a module composed of a neural network, which decodes the output of the encoder and the text input to generate text). The input starts with the start mark of the target sentence, and then the predicted words are added in a loop as input. First, each target word is encoded by embedding, and then position encoding is performed. The generated latent vector representation is passed to the decoder; in the decoder, the latent vector representation of the target word is calculated with the output syntactic latent vector representation and semantic latent vector representation of the encoder for attention calculation (Attention). The attention calculation result is used to generate a vocabulary representation of the target word through dense (representing the fully connected layer in the neural network), thereby generating a similar command text.

[0124] The attention between the decoder and the encoder mentioned above is the interactive attention. The input of this interactive attention is the output of the encoder and the output of the decoder's self-attention. The encoder's self-attention (self-attention mechanism) is the key vector (key) and the value vector (value), and the decoder's self-attention is the query vector (query). The calculation formula using attention is as follows:

[0125]

[0126] In the above formula, Q represents the query vector, K represents the key vector, V represents the value vector, and d k Represents the dimension of the key vector K.

[0127] The above-mentioned method for generating similar command texts performs corpus processing on an artificially collected command data set to generate syntactic templates and similar sentence pairs, uses the syntactic templates and similar sentence pairs to train a preset text generation model, generates a trained similar text generation model, takes the command sentences and syntactic templates in the command data set as input, uses the similar text generation model, and generates the generated similar command text as the final augmented result, thereby realizing the automatic generation of similar command texts, effectively augmenting the command data set, and fully covering various grammatical expressions of device commands.

[0128] Preferably, the processing module 151 includes:

[0129] 1511. An analysis submodule extracts command sentences from the command data set, performs lexical analysis on the command sentences using a lexical analyzer, and generates part-of-speech features.

[0130] Specifically, a lexical analyzer is pre-trained using a corpus annotated by CTB (Chinese Treebank, a Chinese part-of-speech tagging dataset), and the lexical analyzer is used to automatically perform lexical analysis on the manually collected command dataset, and the lexical analysis result of each sentence is a part-of-speech feature.

[0131] Furthermore, the lexical analyzer is mainly composed of the encoder part of the transformer. The input is a sentence, which is embedded in Chinese characters and then positionally encoded. After passing through several layers of transformers, a latent vector is formed. The latent vector is mapped to the part-of-speech feature through a fully connected layer, thereby completing the part-of-speech feature labeling of each character. The ordered string formed by merging the same part-of-speech features becomes a sentence template.

[0132] 1512. A sorting submodule is used to sort the above-mentioned part-of-speech features to generate the above-mentioned syntactic template.

[0133] Among them, the string formed by the sequence of multiple part-of-speech features is used as a syntactic template (representing the shallow syntax of the sentence), and the syntactic templates corresponding to the command sentences under all command types form a syntactic template library, wherein the string formed by the sequence of multiple part-of-speech features is used as a syntactic template as shown in Table 1 below:

[0134] Table 1

[0135]

[0136]

[0137] 1513. A pairing submodule is used to extract command sentences from the above command data set, and to pair the above command sentences with the same command type (such as turn on, turn off, set, adjust, query, etc., which are generally named by a typical device command, such as "turn on the air conditioner" and "turn off the air conditioner") in pairs to generate the above similar sentence pairs.

[0138] Specifically, the manually collected command data set is processed to generate a sentence set (i.e., command sentence set), which is then input into a similar sentence pair generator. The similar sentence pair generator determines whether the sentences are similar based on whether the command type of each sentence is the same, and pairs the sentences of the same command type. The output result is similar sentence pairs, thus forming a similar sentence pair data set.

[0139] Among them, taking the command types and command sentences in Table 1 as an example, a similar sentence pair generator is used to generate a similar sentence pair dataset, and the syntactic annotation of the similar sentence pair dataset is shown in Table 2 below:

[0140] Table 2

[0141]

[0142]

[0143] Preferably, the generation module 153 includes:

[0144] The first encoding submodule 1531 is used to obtain a source sentence based on the command data set, perform semantic encoding on the source sentence, and generate a semantic latent vector of the source sentence.

[0145] The second encoding submodule 1532 is used to obtain the above-mentioned syntactic template, perform syntactic encoding on the above-mentioned syntactic template, and generate a syntactic latent vector.

[0146] Specifically, the syntactic templates corresponding to the command data set are traversed, and the syntactic templates are syntactically encoded in turn to generate the syntactic latent vectors.

[0147] The concatenation submodule 1533 is used to concatenate the semantic latent vector with the syntactic latent vector to generate a concatenated vector.

[0148] The decoding submodule 1534 is used to decode the above-mentioned splicing vector to generate the above-mentioned similar command text.

[0149] Among them, the above semantic latent vector is concatenated with the above syntactic latent vector, and <bos>(Decoder training and decoding auxiliary text symbols, indicating the beginning of the sentence) are decoded together, and the decoder loop predicts each word of the target sentence until it generates <eos>(Decoder training and decoding auxiliary text symbols, indicating the end of the sentence), completing the generation of a target sentence.

[0150] Furthermore, all command sentences in the command data set are traversed, and similar command texts are generated based on all syntactic templates in the syntactic template library as the final augmented result.

[0151] In the prior art, the above-mentioned syntactic template adopts an unsupervised method based on VAE (variational autoencoder model, a neural network model that can realize unsupervised text generation), or directly adopts a transformer model to generate, but there are the following disadvantages: insufficient diversity, the generated sentences are not much different from the input sentences in grammatical structure, and many only replace part of the words; insufficient controllability, many of the generated sentence grammars are unknown, and it cannot be guaranteed to cover the required grammatical types. In view of the above problems, the present invention generates sentences based on syntactic templates to ensure the diversity of generated sentences, guides the generation of similar sentences by inputting the target syntactic template, and ensures the controllability of the output syntactic form.

[0152] Preferably, the second encoding submodule 1532 includes:

[0153] The first generating unit 15321 is used to encode the above-mentioned part-of-speech features corresponding to the above-mentioned syntactic template to generate a part-of-speech feature vector.

[0154] The second generating unit 15322 is used to perform position encoding on the above-mentioned part-of-speech feature vector to generate the above-mentioned syntactic latent vector.

[0155] Among them, position coding is not performed in semantic coding because position coding reflects some syntactic information. The semantic coding here hopes to reduce grammatical factors, so position coding is removed.

[0156] In the above encoding process, the syntactic template is positionally encoded, and the source sentence in the input command dataset is positionally encoded, which ensures that the semantic encoding is independent of the syntax and enhances the robustness of the intent recognition of the command dataset.

[0157] Example 3

[0158] This embodiment provides a computer device, including a memory and a processor, wherein the processor is used to read instructions stored in the memory to perform the following operations:

[0159] Acquire a command data set, perform corpus processing on the command data set, and generate a syntactic template and similar sentence pairs;

[0160] Training a preset text generation model based on the syntactic template and the similar sentence pairs to generate a similar text generation model;

[0161] The command data set and the syntactic template are input into the text generation model to generate similar command texts.

[0162] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0163] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0166] Example 4

[0167] This embodiment provides a computer-readable storage medium, wherein the computer storage medium stores computer-executable instructions, and the computer-executable instructions can execute a method for generating a similar command text in any of the above method embodiments. The storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memories.

[0168] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the invention.< / eos> < / bos> < / eos> < / bos>

Claims

1. A method for generating similar command texts, characterized in that: The steps include: Acquire a command data set, perform corpus processing on the command data set, and generate syntactic templates and similar sentence pairs; The preset text generation model is trained based on the syntactic template and the similar sentence pairs to generate a similar text generation model; wherein the training process of training the preset text generation model based on the syntactic template and the similar sentence pairs is as follows: syntactically encode the syntactic template of the target sentence to generate a latent vector representation of the syntactic template of the target sentence; semantically encode the text of the source sentence to generate a latent vector representation of the semantics of the source sentence; concatenate the latent vector representation of the syntactic template of the target sentence and the latent vector representation of the semantics of the source sentence, and send them together with the text of the target sentence into the decoder for decoding to obtain a predicted target sentence; take the predicted result and the target sentence as input, calculate the reconstruction loss, back-propagate and update the model parameters to complete the model training; Inputting the command data set and the syntactic template into the text generation model to generate similar command texts; The step of acquiring a command data set, performing corpus processing on the command data set, and generating a syntactic template and similar sentence pairs includes: Extracting command sentences from the command data set, performing lexical analysis on the command sentences using a lexical analyzer, and generating part-of-speech features; Sorting the part-of-speech features to generate the syntactic template; Command sentences are extracted from the command data set, and the command sentences with the same command type are paired up to generate the similar sentence pairs.

2. The method for generating similar command text according to claim 1, characterized in that: The step of inputting the command data set and the syntactic template into the text generation model to generate similar command texts includes: Acquire a source sentence based on the command data set, perform semantic encoding on the source sentence, and generate a source sentence semantic latent vector; Acquire the syntactic template, perform syntactic encoding on the syntactic template, and generate a syntactic latent vector; Concatenating the semantic latent vector with the syntactic latent vector to generate a concatenated vector; The concatenated vector is decoded to generate the similar command text.

3. The method for generating similar command text according to claim 2, characterized in that: The obtaining the syntactic template, performing syntactic encoding on the syntactic template, and generating a syntactic latent vector includes: Encoding the part-of-speech feature corresponding to the syntactic template to generate a part-of-speech feature vector; Position encoding is performed on the part-of-speech feature vector to generate the syntactic latent vector.

4. The method for generating similar command text according to claim 2, characterized in that: The acquiring the syntactic template, performing syntactic encoding on the syntactic template, and generating a syntactic latent vector further includes: The syntactic templates corresponding to the command data set are traversed, and the syntactic templates are syntactically encoded in sequence to generate the syntactic latent vectors.

5. A device for generating similar command texts, characterized in that: include: A processing module, used for acquiring a command data set, performing corpus processing on the command data set, and generating a syntactic template and similar sentence pairs; A training module is used to train a preset text generation model based on the syntactic template and the similar sentence pairs to generate a similar text generation model; wherein the training process of training the preset text generation model based on the syntactic template and the similar sentence pairs is as follows: syntactically encode the syntactic template of the target sentence to generate a latent vector representation of the syntactic template of the target sentence; semantically encode the text of the source sentence to generate a latent vector representation of the semantics of the source sentence; concatenate the latent vector representation of the syntactic template of the target sentence and the latent vector representation of the semantics of the source sentence, and send them together with the text of the target sentence into a decoder for decoding to obtain a predicted target sentence; take the predicted result and the target sentence as input, calculate the reconstruction loss, back-propagate and update the model parameters to complete the model training; A generation module, used for inputting the command data set and the syntactic template into the text generation model to generate similar command text; The processing module comprises: An analysis submodule, used for extracting command sentences from the command data set, performing lexical analysis on the command sentences using a lexical analyzer, and generating part-of-speech features; A sorting submodule, used to sort the part-of-speech features and generate the syntactic template; The pairing submodule is used to extract command sentences from the command data set, and pair the command sentences with the same command type in pairs to generate similar sentence pairs.

6. The device for generating similar command text according to claim 5, characterized in that: The generating module comprises: A first encoding submodule, configured to obtain a source sentence based on the command data set, perform semantic encoding on the source sentence, and generate a semantic latent vector of the source sentence; A second encoding submodule is used to obtain the syntactic template, perform syntactic encoding on the syntactic template, and generate a syntactic latent vector; A concatenation submodule, used for concatenating the semantic latent vector with the syntactic latent vector to generate a concatenated vector; The decoding submodule is used to decode the splicing vector to generate the similar command text.

7. A computer device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store a computer program, and the processor is configured to call the computer program to execute the steps of the method according to any one of claims 1 to 4.

8. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.