A method and system for generating target domain text
By receiving the topic parameters and word count range in the user's request, the target domain vocabulary list and conditional word sequence are generated, the text generation model is called and the decoded word sequence is screened, which solves the problem of difficulty in controlling the length and theme consistency of text generation in the existing technology. High-quality text generation is achieved.
Patent Information
- Application Number
- CN202410918161.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-07-10
AI Technical Summary
In teaching or other text application scenarios, it is difficult to generate text that conforms to the theme and precisely controls the length of the text with existing technology, which can easily lead to problems such as content exceeding the outline or word count inconsistency.
By receiving the topic parameters, text type parameters and word range in the user request, we generate the target domain vocabulary and conditional word sequence, call the text generation model and use the word range and word list to filter the decoded word sequence to ensure that the quality and length of the text meet the requirements. .
It achieves the generation of text content that meets expectations, avoids redundant content or deviation from the topic, and ensures the professionalism and relevance of the text.
Smart Images

Figure CN118468822B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a method and system for generating text in a target domain. Background Art
[0002] In teaching or other text application scenarios, it is necessary to generate supporting text that matches the topic. Regarding automatic text generation, there are challenges in the prior art in ensuring that the content does not deviate from the predetermined topic and does not contain inappropriate information, which may cause the generated text content to be out of scope, that is, beyond the topic or scope specified by the user. In addition, when generating text of a specific length, it may be difficult to accurately control the number of words, exceeding or falling short of the word limit required by the user. Summary of the invention
[0003] The main purpose of the present invention is to provide a method and system for generating target domain text. Through the theme parameters and text type parameters, the system can generate conditional word sequences related to specific domains and types; use the word count range and the target domain vocabulary to screen the decoded word sequence, control the length and quality of the generated text, and avoid content redundancy or deviation from the topic. By accurately controlling various aspects of the text, the end user can obtain more satisfactory and expected text content.
[0004] In order to achieve the above objectives, the embodiments of the present application provide the following technical solutions:
[0005] According to a first aspect of an embodiment of the present application, a method for generating target domain text is provided, the method comprising:
[0006] receiving a target domain text generation request sent by a user device, wherein the target domain text generation request carries a subject parameter, a text type parameter, a word count range, and a domain text attribute;
[0007] Generate a target domain vocabulary according to the subject parameters and the text data set corresponding to the target domain;
[0008] Generate a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute;
[0009] Calling the target domain text generation model to obtain a decoding word sequence based on the conditional word sequence;
[0010] The target decoding word sequence is screened out using the word count range and the target domain word list, and decoded into the target domain text.
[0011] The calling of the target domain text generation model to obtain a decoding word sequence based on the conditional word sequence includes:
[0012] Calling the target domain text generation model to calculate a probability value set of a candidate word at the next sequence position in the conditional word sequence;
[0013] Sorting the probability values in the probability value set from large to small;
[0014] The word with the largest probability value is added to the initialization word sequence to generate the decoding word sequence.
[0015] Optionally, the using the word count range and the target domain vocabulary to select a target decoding word sequence includes:
[0016] Decoding the decoding word sequence to obtain corresponding decoding words;
[0017] Find whether the decoding vocabulary exists in the target domain vocabulary. If not, delete the current word from the decoding word sequence, add the word corresponding to the next digit of the maximum value in the probability value sorting to the decoding word sequence, and continue to perform subsequent steps; if it exists, add the decoding vocabulary to the end of the conditional word sequence;
[0018] Repeat the above steps until the conditional word sequence meets the word number range to obtain a target decoding word sequence.
[0019] Optionally, generating a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute includes:
[0020] Generate conditional text according to the subject parameter, the text type parameter and the domain text attribute;
[0021] The conditional text is encoded to obtain the conditional word sequence.
[0022] Optionally, generating the conditional text according to the subject parameter, the text type parameter and the field text attribute includes:
[0023] Serializing the domain text attributes to obtain domain text attribute processing results;
[0024] Serializing the subject parameter and the text type parameter to obtain an annotation content processing result;
[0025] The start identifier of the domain text attribute, the domain text attribute processing result, the start identifiers of the subject parameter and the text type parameter, the annotation content processing result and the identifier of the text to be generated are sequentially spliced to obtain the conditional text.
[0026] Optionally, the target domain text generation model is trained according to the following steps:
[0027] Based on the training data set, an input word sequence, a target word sequence and a target identification word sequence are obtained by processing;
[0028] Batch sampling the input word sequence, the target word sequence and the target identification word sequence to obtain a batch word sequence, a batch target word sequence and a batch target identification word sequence;
[0029] Inputting the batch of word sequences into a pre-trained target domain text generation model to obtain a probability distribution of predicted words;
[0030] Calculate the cross entropy loss between the probability distribution of the predicted word and the target word sequence;
[0031] Calculate the gradient of the target domain text generation model and update the weights by minimizing the cross entropy loss;
[0032] Repeat the above steps until the number of training rounds reaches the preset number, and then the training stops.
[0033] Optionally, the training data set includes material text; the processing based on the training data set to obtain the input word sequence, the target word sequence and the target identification word sequence includes:
[0034] Serializing and encoding the training data set to obtain a training conditional word sequence;
[0035] Constructing a sequence of zero identifiers having the same length as the training conditional word sequence;
[0036] The training generated text is obtained by sequentially splicing the start mark of the material text, the material text, and the end mark of the material text, and encoding is performed to obtain a training generated word sequence;
[0037] Constructing a 1-identifier sequence having the same length as the training generated vocabulary sequence;
[0038] The training conditional word sequence and the training generated word sequence are concatenated to obtain an input word sequence, and the 0 identification sequence and the 1 identification sequence are concatenated to obtain an input identification sequence;
[0039] The input word sequence is shifted to the left by one word position to obtain a target word sequence;
[0040] Adding 1 identification word at the end of the input identification sequence and shifting the word position to the left to obtain a target identification word sequence;
[0041] Repeat the above steps until the training data set is processed into an input word sequence, a target word sequence, and a target identification word sequence.
[0042] Optionally, the training data set further includes subject parameters, text type parameters and domain text attributes corresponding to the material text; the serialization and encoding of the training data set to obtain a training conditional word sequence includes:
[0043] Serializing the domain text attributes corresponding to the material text to obtain a training domain text attribute processing result;
[0044] Serializing the subject parameters and text type parameters corresponding to the material text to obtain a training annotation content processing result;
[0045] The starting identifier of the domain text attribute of the material text, the processing result of the training domain text attribute, the starting identifier of the subject parameter and the text type parameter of the material text, and the processing result of the training annotation content are sequentially spliced to obtain the training condition text;
[0046] The training condition text is encoded to obtain the training condition word sequence.
[0047] Optionally, generating a target domain vocabulary according to the subject parameter and the text data set corresponding to the target domain includes:
[0048] Extracting all words under the subject parameters from the text data set corresponding to the target field according to the subject parameters as a first candidate word list;
[0049] Performing grammatical standardization processing on the candidate words in the first candidate word list respectively to obtain a second candidate word list;
[0050] The first candidate word list and the second candidate word list are combined to obtain the target domain word list.
[0051] According to a second aspect of an embodiment of the present application, a target domain text generation system is provided, the system comprising:
[0052] A request receiving module, configured to receive a target domain text generation request sent by a user device, wherein the target domain text generation request carries a subject parameter, a text type parameter, a word count range, and domain text attributes;
[0053] A target domain vocabulary module, used to generate a target domain vocabulary according to the subject parameters and a text data set corresponding to the target domain;
[0054] A conditional word sequence module, used to generate a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute;
[0055] A decoding word sequence module is used to call the target domain text generation model to obtain a decoding word sequence based on the conditional word sequence;
[0056] The target domain text generation module is used to select a target decoding word sequence by using the word count range and the target domain word list, and decode it into the target domain text.
[0057] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect above.
[0058] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored. The computer-readable instructions can be executed by a processor to implement the method described in the first aspect above.
[0059] In summary, the embodiment of the present application provides a method and system for generating text in a target domain, by receiving a target domain text generation request sent by a user device, the target domain text generation request carries a subject parameter, a text type parameter, a word range and a domain text attribute; a target domain vocabulary is generated according to the subject parameter and the text data set corresponding to the target domain; a conditional word sequence is generated according to the subject parameter, the text type parameter and the domain text attribute; a target domain text generation model is called to obtain a decoding word sequence based on the conditional word sequence; a target decoding word sequence is screened out using the word range and the target domain vocabulary, and decoded into a target domain text. Through the subject parameter and the text type parameter, the system can generate text related to a specific domain and type; by constructing a target domain vocabulary and a conditional word sequence, a structured information basis is provided for text generation. The decoding word sequence is screened using the word range and the target domain vocabulary to control the length and quality of the generated text, and avoid content redundancy or deviation from the subject. By precisely controlling various aspects of the text, the end user can obtain more satisfactory and expected text content. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.
[0061] The structures, proportions, sizes, etc. illustrated in this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with the technology. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no substantial technical significance. Any structural modification, change in proportion or adjustment of size shall still fall within the scope of the technical contents disclosed in the present invention without affecting the effects and purposes that can be achieved by the present invention.
[0062] Figure 1 A schematic diagram of a target domain text generation process provided in an embodiment of the present application;
[0063] Figure 2 Generate a general logic diagram for the target domain text provided in the embodiment of the present application;
[0064] Figure 3 A block diagram of a target domain text generation system provided in an embodiment of the present application;
[0065] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown;
[0066] Figure 5 A schematic diagram of a computer-readable storage medium provided in an embodiment of the present application is shown.
[0067] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. 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] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0070] In addition, in the present invention, descriptions such as "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0071] In the present invention, unless otherwise clearly specified and limited, the terms "connection", "fixation", etc. should be understood in a broad sense. For example, "fixation" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0072] In addition, the technical solutions between the various embodiments of the present invention can be combined with each other, but it must be based on the fact that ordinary technicians in the field can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0073] Figure 1 A method for generating target domain text provided by an embodiment of the present application is shown, and the method comprises:
[0074] Step 101: receiving a target domain text generation request sent by a user device, wherein the target domain text generation request carries a subject parameter, a text type parameter, a word range, and domain text attributes;
[0075] Step 102: Generate a target domain vocabulary according to the subject parameters and the text data set corresponding to the target domain;
[0076] Step 103: Generate a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute;
[0077] Step 104: calling the target domain text generation model to obtain a decoding word sequence based on the conditional word sequence;
[0078] Step 105: Filter out a target decoding word sequence using the word count range and the target domain word list, and decode it into the target domain text.
[0079] In a possible implementation, in step 104, the calling of the target domain text generation model to obtain a decoding word sequence based on the conditional word sequence includes:
[0080] The target domain text generation model is called to calculate a probability value set of candidate words at the next sequence position in the conditional word sequence; the probability values in the probability value set are sorted from large to small; the word with the largest probability value is added to the initialization word sequence to generate the decoding word sequence.
[0081] First, the conditional word sequence is received, and then the probability value set of the possible candidate words in the next position in the sequence is calculated. In terms of the predictive ability of the language model, the model will predict the next most likely word based on the previous word sequence. After obtaining the probability value set of the candidate words, the model sorts these probability values from large to small. Find the most likely candidate word, that is, the word with the highest probability value. After the sorting is completed, the model will select the word with the largest probability value and add it to the current decoded word sequence. This operation will be repeated until the generated decoded word sequence reaches the required length or meets other termination conditions.
[0082] In a possible implementation, in step 105, the step of selecting a target decoding word sequence by using the word number range and the target domain word list includes:
[0083] Decode the decoding word sequence to obtain the corresponding decoding vocabulary; search whether the decoding vocabulary exists in the target domain vocabulary; if not, delete the current word from the decoding word sequence, add the word corresponding to the next digit of the maximum value in the probability value sorting to the decoding word sequence, and continue to execute subsequent steps; if it exists, add the decoding vocabulary to the end of the conditional word sequence; repeat the above steps until the conditional word sequence meets the word number range, and obtain the target decoding word sequence.
[0084] If the decoding vocabulary exists in the target domain vocabulary, it means that the vocabulary meets the domain requirements. Add it to the end of the conditional vocabulary sequence and continue to generate the next vocabulary. If the decoding vocabulary does not exist in the target domain vocabulary, it means that the vocabulary does not meet the domain requirements and needs to be adjusted. Delete the words that do not meet the requirements from the current decoding vocabulary sequence. Sort by probability value, select the word corresponding to the next digit with the largest probability value, and add it to the decoding vocabulary sequence. Continue to decode and filter the new decoding vocabulary sequence, repeating the above steps until the entire conditional vocabulary sequence meets the specified word count range. When the conditional vocabulary sequence reaches the required word count range, stop the filtering process, and the resulting decoding vocabulary sequence is the target decoding vocabulary sequence. Ensure that the generated text meets the word count requirements and uses the professional vocabulary of the target domain, thereby improving the quality and relevance of the text.
[0085] In a possible implementation, in step 103, generating a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute includes:
[0086] Generate conditional text according to the subject parameter, the text type parameter and the domain text attribute; and encode the conditional text to obtain the conditional word sequence.
[0087] In a possible implementation, in step 103, generating conditional text according to the subject parameter, the text type parameter and the domain text attribute includes:
[0088] The domain text attribute is serialized to obtain a domain text attribute processing result; the subject parameter and the text type parameter are serialized to obtain an annotation content processing result; the starting identifier of the domain text attribute, the domain text attribute processing result, the starting identifiers of the subject parameter and the text type parameter, the annotation content processing result and the text identifier to be generated are sequentially concatenated to obtain the conditional text.
[0089] The domain text attributes are serialized, that is, the domain-related information is converted into a format that can be understood and processed by the model, and the domain text attribute processing results are obtained. The subject parameters and text type parameters are also serialized to obtain the annotation content processing results. The processed domain text attributes, subject parameters and text type parameters are spliced together in a certain order to form conditional text. The spliced conditional text is encoded and converted into a sequence of words that can be understood by the model. This encoding process may involve operations such as converting the text into word vectors and tokenization. Use the encoded conditional word sequence as input to call the target domain text generation model to generate a decoded word sequence.
[0090] It can effectively integrate key information such as domain knowledge, topics, and text types into the generation process, thereby generating text that better meets user needs. At the same time, through serialization and splicing processing, it can ensure that the model can take all relevant conditions into account when generating text.
[0091] In a possible implementation, the target domain text generation model is trained according to the following steps:
[0092] Based on the training data set, processing is performed to obtain an input word sequence, a target word sequence and a target identification word sequence; batch sampling is performed on the input word sequence, the target word sequence and the target identification word sequence to obtain a batch word sequence, a batch target word sequence and a batch target identification word sequence; the batch word sequence is input into a pre-trained target domain text generation model to obtain a probability distribution of predicted words; the cross entropy loss between the probability distribution of predicted words and the target word sequence is calculated; the gradient of the target domain text generation model is calculated by minimizing the cross entropy loss and the weights are updated; the above steps are repeated until the number of training rounds reaches a preset number, and the training stops.
[0093] It can make full use of the information in the training data, including text content, topics, types, and attributes, to improve the relevance and accuracy of the generated text. At the same time, through the optimization of cross entropy loss and gradient descent, the model can learn the ability to generate high-quality text.
[0094] In a possible implementation, the training data set includes material text; the step of obtaining the input word sequence, the target word sequence, and the target identification word sequence by processing based on the training data set includes:
[0095] The training data set is serialized and encoded to obtain a training conditional word sequence; a 0 identifier sequence with the same word sequence length of the training conditional word sequence is constructed; a training generated text is spliced in the order of the start identifier of the material text, the material text, and the end identifier of the material text, and encoded to obtain a training generated word sequence; a 1 identifier sequence with the same word sequence length of the training generated word sequence is constructed; the training conditional word sequence and the training generated word sequence are spliced to obtain an input word sequence, and the 0 identifier sequence and the 1 identifier sequence are spliced to obtain an input identifier sequence; the input word sequence is offset to the left by 1 word position to obtain a target word sequence; a 1 identifier word is added to the end of the input identifier sequence and is offset to the left by 1 word position to obtain a target identifier word sequence; the above steps are repeated until the training data set is processed into an input word sequence, a target word sequence, and a target identifier word sequence.
[0096] Each material text in the training dataset is serialized and decomposed into tokens or smaller units, such as characters or subwords. Then, the serialized tokens are encoded into a format that the model can understand, such as integer indexes or word vectors, to obtain a training conditional token sequence. For the training conditional token sequence, a 0 identifier sequence with the same length as the token sequence is created to distinguish different parts of the sequence or as padding.
[0097] Concatenate the material text in a specific order (start mark, material text, end mark) to form the training generated text. Encode the concatenated text to obtain the training generated word sequence. Create a 1-marker sequence with the same length as the word sequence for the training generated word sequence to mark the beginning or end of the sequence.
[0098] Concatenate the training conditional word sequence and the training generated word sequence to form the input word sequence. Concatenate the 0 identifier sequence and the 1 identifier sequence to form the input identifier sequence. Shift the input word sequence to the left by 1 word position, that is, shift each word in the sequence to the left by one position to obtain the target word sequence. Used for training sequence generation models to predict the next word. Add a 1 identifier word to the end of the input identifier sequence, and then shift it to the left by 1 word position to obtain the target identifier word sequence. Repeat the above steps until all the material texts in the training data set are processed into input word sequences, target word sequences, and target identifier word sequences. Use these processed sequences as input and targets to train the target domain text generation model, usually using a sequence generation model such as a recurrent neural network (RNN) or a transformer.
[0099] The above steps provide the model with structured and labeled training data, which helps the model learn how to generate text that meets specific conditions.
[0100] In a possible implementation, the training data set further includes a subject parameter, a text type parameter, and a domain text attribute corresponding to the material text; and the training data set is serialized and encoded to obtain a training conditional word sequence, including:
[0101] The domain text attributes corresponding to the material text are serialized to obtain the training domain text attribute processing results; the subject parameters and text type parameters corresponding to the material text are serialized to obtain the training annotation content processing results; the starting identifier of the domain text attribute of the material text, the training domain text attribute processing results, the starting identifiers of the subject parameters and text type parameters of the material text, and the training annotation content processing results are sequentially spliced to obtain the training condition text; the training condition text is encoded to obtain the training condition word sequence.
[0102] In a possible implementation, in step 102, generating a target domain vocabulary according to the subject parameters and the text data set corresponding to the target domain includes:
[0103] According to the subject parameters, all words under the subject parameters are extracted from the text data set corresponding to the target domain as a first candidate word list; grammatical standardization is performed on the candidate words in the first candidate word list to obtain a second candidate word list; the first candidate word list and the second candidate word list are merged to obtain the target domain word list.
[0104] Based on the provided topic parameters, all words related to the topic are retrieved from the text dataset corresponding to the target domain. These words constitute the preliminary candidate word list, which is the vocabulary directly related to the specific topic. Each candidate word in the first candidate word list is further subjected to grammatical standardization. This may include operations such as stemming, lemmatization, or part-of-speech tagging, with the goal of converting the vocabulary into a standard form for unified processing and analysis. The vocabulary after grammatical standardization constitutes the second candidate word list. It helps to ensure that the vocabulary in the vocabulary is grammatically correct and can be used more effectively by the text generation model. The first candidate word list and the second candidate word list are merged to form the final target domain vocabulary. This merging process may involve removing duplicates, sorting, or other processing to ensure the quality and consistency of the vocabulary.
[0105] The target domain vocabulary finally generated will be used in the text generation task, such as the screening and decoding word sequence mentioned in step 105, to ensure that the generated text meets the requirements of the target domain in terms of vocabulary usage. Ensuring that the generated text is closely related to the specific domain at the vocabulary level improves the relevance and professionalism of the text. At the same time, through grammatical standardization processing, the accuracy and usability of the vocabulary can be improved.
[0106] The following is combined with Figure 2 The overall process of the text generation method for the target field based on artificial intelligence provided in the embodiment of the present application is described in detail, and machine learning technology, especially the sequence generation model in natural language processing, is used to generate target text that conforms to the field set by the user.
[0107] Phase 1: Determine the training dataset based on the annotation content specified by the user.
[0108] Step 1: Collect the material texts corresponding to each target field in the database.
[0109] Step 2: Obtain the annotation content of the above material text imported or set by the user. The annotation content can be annotated by experts in the target field, and the annotation content includes subject parameters, organization method and its attributes, difficulty, word range and appropriate field text attributes.
[0110] i. Topic parameters: the topics covered by the text in the target field materials.
[0111] ii. Text type parameters: including dialogue, statement, role-playing, etc. The specific attributes of each text type parameter include:
[0112] a. When the text type parameter belongs to the dialogue organization method, the attributes include: number of dialogue rounds, gender and name of the dialogue character, etc.
[0113] b. When the text type parameter belongs to narrative organization mode, the attributes include: letter, news, story, biography, etc.
[0114] c. When the text type parameter belongs to the role-playing organization method, the attributes include: scenario type, role type, rule type, etc.
[0115] iii. Difficulty level: the difficulty of the text of the material.
[0116] iv. Word count range: the word count range of the material text.
[0117] v. Text attributes: that is, the text attributes of the field to which the material is suitable.
[0118] Step 3: According to the domain text attribute information in the annotation content, add the corresponding domain text attribute information. Domain text attributes refer to the language elements used in a specific field, including vocabulary, phrases, sentence patterns, grammatical structures, etc., which are the basic components of the text in this field. For example, in the field of computer science, vocabulary: "algorithm", "programming", "data structure"; phrases: "user interface", "cloud computing"; sentence patterns: "In order to optimize performance,..."; grammar: use professional terms and precise descriptions, such as "the time complexity of this algorithm is O(n).".
[0119] Step 4: Combine the above material text, annotation content and domain text attributes to form training data.
[0120] The second stage: training the target domain text generation model based on the above training dataset.
[0121] Design a pre-trained target domain text generation model, including embedding layer, encoding layer and language layer, using Transformer architecture and autoregressive self-attention mechanism. Specifically include:
[0122] a. Embedding layer: The embedding layer consists of a word embedding layer and a position embedding layer. The word embedding layer receives a word sequence and outputs a word embedding vector sequence. The position embedding layer receives a position sequence and outputs a position vector sequence. The position sequence (PositionalEncoding) is used to provide the model with information about the position of a word in a sentence. The position sequence corresponds to the word sequence and has the same length. When calculating, the model constructs a position sequence of the same length based on the word sequence. The sequence of position encodings is [0,1,2,3,4,…, n]. The word embedding vector (embedded representation from the word sequence) and the position encoding vector are added or concatenated to form the final representation of each word, which will be sent to the encoding layer of the Transformer model.
[0123] The position sequence is usually a vector sequence of the same length as the token sequence, with each vector corresponding to a position in the sequence. These vectors are predefined and are usually generated by mathematical functions to ensure that the encoding vectors of different positions are unique. Therefore, a method is needed to tell the model the relative or absolute position of each word in the sequence.
[0124] b. Encoding layer: It consists of multiple Transformer layers, with an autoregressive self-attention mechanism in the middle. The encoding layer receives a sequence of word embedding vectors and a sequence of position vectors, and outputs a sequence of semantic latent vectors. The encoding layer takes these enhanced word embedding vectors as input and further processes them through the self-attention mechanism and feedforward network to extract deep semantic information in the sequence.
[0125] c. Language layer: It consists of a fully connected layer, which receives the semantic latent vector sequence output by the encoding layer. After calculation by the fully connected layer, the probability distribution of each word is calculated by the Softmax function. The output of the encoding layer is sent to the language layer, which is usually a fully connected layer, to predict the probability distribution of the next word.
[0126] Based on the above structure, training the target domain text generation model according to the training data includes the following process:
[0127] Step 1: Process the training data to obtain a set of word sequences, which specifically includes:
[0128] i. Traverse the training data, and for each document under the training data, serialize the domain text attributes and annotation content respectively to obtain the domain text attribute serialization results and the annotation content serialization results.
[0129] ii. Concatenate the text in the order of the domain text attribute start identifier, the domain text attribute serialization result, the annotation content start identifier, and the annotation content serialization result to form the training condition text.
[0130] iii. Use the word segmenter to perform word segmentation encoding on the training condition text to obtain the training condition word sequence.
[0131] iv. Construct a 0-marker sequence of equal length based on the training conditional word sequence.
[0132] v. Concatenate the text in the order of material text identifier, material text, and end identifier to obtain the training generated text.
[0133] vi. Use the word segmenter to perform word segmentation encoding on the training generated text to obtain the training generated word sequence.
[0134] vii. Generate a word sequence based on the training and construct a 1-mark sequence of the same length.
[0135] viii. The training conditional word sequence and the training generated word sequence generated above are concatenated to obtain an input word sequence; the 0 identifier sequence and the 1 identifier sequence are concatenated to obtain an input identifier sequence.
[0136] ix. Shift the input word sequence by one position to the left to obtain the target word sequence. Add one identification word to the end of the input identification sequence and shift it by one position to the left to obtain the target identification word sequence.
[0137] x. Repeat the above steps until each document in the training data, that is, all the training data, is encoded into an input word sequence, a target word sequence, and a target identification word sequence.
[0138] In the sequence generation task, the model needs to distinguish which words are conditional text (i.e., the input part) and which are generated text (i.e., the part that the model needs to generate). By constructing 0-identifier sequences and 1-identifier sequences, the model can identify which words belong to conditional text and which belong to generated text. By using different identifier sequences, the model can be guided to pay more attention to conditional text when generating text, and to focus on generated text when decoding conditional text.
[0139] Step 2: Use the gradient descent algorithm to train the target domain text generation model, which specifically includes the following process:
[0140] i. Perform batch sampling without replacement on the input word sequence, target word sequence, and target identification word sequence in the training set to obtain a batch word sequence, a batch target word sequence, and a batch target identification word sequence.
[0141] ii. Input the batch word sequence into the target domain text generation model to obtain the probability distribution of the predicted words.
[0142] iii. Calculate the cross entropy loss between the probability distribution of the predicted word and the target sequence according to the following formula.
[0143]
[0144] Where p represents the probability distribution of the predicted word, y is the target sequence, w is the batch target identification word sequence, and N is the batch target word sequence length. c and C are the current word and all the words in the vocabulary, respectively.
[0145] iv. Minimize the cross entropy loss through the optimizer, calculate the gradient of the estimated model and complete the weight update.
[0146] v. Repeat the above steps until all data are sampled.
[0147] vi. Training stops until the preset number of rounds is reached.
[0148] In terms of training details, the following settings were made: for the optimizer, Adamw was selected, the learning rate was set to 3e-5, the weight decay coefficient was set to 0.01, β1 was 0.9, and β2 was 0.95; for the learning rate scheduling strategy, the linear decay strategy was selected, the decay coefficient was 0.1, and the warm-up was 100 steps. A total of 2000 steps were trained, the batch size was set to 8, 4 A800 cards were selected for training, and zero-2 was selected for parallel mode.
[0149] The third stage: in response to the user's request to generate the target domain text, a conditional word sequence is generated according to the annotation content and domain text attributes.
[0150] Step 1: Get a whitelist of words. Decide on a list of words and make sure that only those words are used in the material you generate.
[0151] If it is an English text, the white-name word list in the embodiment of the present application is obtained in the following manner: extract the words that appear in the field according to the organizational dimension of each field from the target field text database as candidate words. Perform part-of-speech restoration on the candidate words to obtain a second candidate word. Merge the candidate word and the second candidate word to obtain a white-name word list. Extract the words in each field from the target field text database, perform part-of-speech restoration, and obtain a white-name word list.
[0152] In Chinese text processing, Chinese does not have the same morphological changes as English. The "part-of-speech restoration" of Chinese usually refers to converting vocabulary into its standard or basic form, rather than morphological restoration. If it is Chinese text, the white-name word list in the embodiment of the present application is obtained in the following way: from the target domain text database, according to the organizational dimension of each domain, extract the vocabulary that appears in the domain as candidate words. Standardize the candidate words to obtain the second candidate words. Merge the candidate words and the second candidate words to obtain the white-name word list.
[0153] The standardization process may include the following steps: Vocabulary standardization: Ensure that the standard form of vocabulary is used, for example, avoid using typos or non-standard abbreviations. Removal of dialect vocabulary: If the material needs to be aimed at a wide range of Chinese speakers, it may be necessary to remove or replace dialect vocabulary from a specific region and use Mandarin vocabulary. Restoration of word meaning: In some cases, it may be necessary to convert polysemous words into their most common meanings to avoid ambiguity. Synonym replacement: When it is necessary to control the difficulty of the text or adapt to a specific reader group, it may be necessary to replace some uncommon or difficult-to-understand words with more common synonyms. Removal or replacement of uncommon words: For educational materials, especially those for beginners, it may be necessary to remove or replace uncommon or uncommon words. Grammatical standardization: Ensure that the text conforms to the grammatical standards of Chinese, including correct word order, collocation and sentence structure.
[0154] Step 2: Obtain the domain text attributes and annotation content set by the user as generation conditions.
[0155] Step 3: Serialize the domain text attributes and annotation content to form conditional text; and use the word segmenter to encode it to obtain the conditional word sequence.
[0156] Calculate the initial conditional word sequence according to the given conditions: a. Serialize the domain text attributes. b. Serialize the annotation content. c. Concatenate the domain text attribute start identifier + domain text attribute serialization result + annotation content start identifier + annotation content serialization result + to-be-generated text identifier to obtain the conditional text. d. Use the word segmenter to encode the conditional text to obtain the conditional word sequence.
[0157] Step 4: Initialize the decoding word sequence, that is, the decoding sequence is empty when it starts to be generated.
[0158] The fourth stage: Generate decoding word sequence based on the target domain text generation model.
[0159] Step 1: Use the trained target domain text generation model to predict the next word in the text generation process.
[0160] a: Input the conditional word sequence: Input the prepared conditional word sequence into the trained target domain text generation model.
[0161] b: Predict word probability: Based on the input conditional word sequence, predict the next possible word and calculate a probability value for each possible word. This probability reflects the possibility that the model believes each word is the next word.
[0162] c: Sort words: Sort all possible words according to their probability values from high to low.
[0163] d: Select the word with the highest probability: Select the word with the highest probability as the next word to be predicted.
[0164] e: Add to the decoding sequence: Add the word with the highest probability to the decoding sequence.
[0165] Use the trained model to predict the next word and select the word with the highest probability. Input the conditional word sequence into the target domain text generation model to predict the probability of the next word. The next word probability refers to the word probability represented by the semantic latent vector at the last position. Sort the words from large to small according to the word probability, and add the current word with the highest probability to the decoded word sequence. In this way, the model can gradually build a coherent text sequence.
[0166] Step 2: Decode the above decoding word sequence to generate temporary text.
[0167] The fifth stage: using the annotation content and the white-name word list to select the target decoding word sequence, and decode it into the target domain text.
[0168] Step 1: Traverse the words in the temporary text to determine whether the word exists in the whitelist. If the currently predicted word is not on the whitelist, remove the current word from the decoded word sequence, and the generation process will go back to the previous step to re-predict the word corresponding to the next probability value until a word on the whitelist is found. If it exists, continue.
[0169] Step 2: Replace the text identifier to be generated at the end of the conditional word sequence with the current word.
[0170] Step 3: Repeat the above steps and iterate continuously until the temporary text obtained by decoding the decoding word sequence meets the annotation conditions or reaches a predetermined length, that is, the target domain material text is obtained.
[0171] Filtering through the whitelist ensures that all words are within the allowed range. Before adding the predicted word to the decoding word sequence, it is necessary to check whether the word exists in the whitelist. If the word is on the whitelist, it means that it is a word that appears in the textbook and can be accepted and added to the decoding sequence. If the predicted word is not on the whitelist, that is, it is not a word in the textbook, then the word will not be added to the decoding sequence. This ensures that the generated text only contains words that students should be familiar with, thereby ensuring the accuracy of the material.
[0172] The embodiments of this application involve data preprocessing, model training, condition setting, and final text generation and screening. This method can be applied to a variety of fields, such as news generation, story creation, listening material generation, technical document writing, etc.
[0173] English listening materials refer to resources produced in English for listening training or teaching. In design, the content should be limited to what students can understand. For example, listening materials for primary school should match the vocabulary, grammar and life experience learned by primary school students. The following is an example of the generation of actual listening materials to explain the technical solution. It is divided into three parts: data collection, model training and target material generation to further explain the technical solution.
[0174] Phase 1: Collect training data.
[0175] Step 1: Collect the text materials from existing English listening test questions. For example, collect thousands of English listening test materials for compulsory education.
[0176] Step 2: English listening test experts will annotate the text of the material. The annotations include the theme, organization and its attributes, difficulty level, word range and appropriate teaching materials unit.
[0177] i. Theme: The theme of the text in the English listening material.
[0178] ii. Organizational methods and attributes under various organizational methods. The organizational methods and attributes under various organizational methods specifically include dialogue, statement, role-playing, etc. The specific subordinate attributes of each organizational method include: a. When the material belongs to the dialogue organizational method, the attributes include: number of dialogue rounds, gender and name of the dialogue character, etc. b. When the material belongs to the narrative organizational method, the attributes include: letters, news, stories, biographies, etc. c. When the material belongs to the role-playing organizational method, the attributes include: scenario type, role type, rule type, etc.
[0179] iii. Difficulty level: the difficulty of the listening material. In the embodiment of the present application, the difficulty level is divided into three categories, namely, difficult, medium, and easy.
[0180] iv. Word count range: the word count range of the listening material, that is, the word count range of the material, which can be divided into "0-50", "50-100", "100-150", "150-200", "200-250", "250-300", "300-350", "350-400" and "400-500" in the embodiment of the present application.
[0181] v. Textbook unit: the textbook and unit that the material is suitable for, such as Unit 1 of the first volume of the seventh grade textbook and Unit 7 of the first volume of the eighth grade textbook.
[0182] Step 3: According to the textbook units in the annotation content, add the corresponding textbook unit information, including: vocabulary, phrases, sentence patterns, grammar, objectives and other elements.
[0183] According to the annotation content, the relevant textbook unit information is associated with the material. The unit information in this example specifically includes the following elements: Vocabulary: new words learned in this unit of the textbook. Phrases: important English phrases learned in this unit of the textbook. Sentence patterns: important English sentence patterns learned in this unit of the textbook. Grammar: grammar knowledge learned in this unit of the textbook. Objectives: teaching objectives involved in this unit of the textbook.
[0184] Step 4: Combine the above material text, annotation content and teaching material unit information into training data.
[0185] The second stage: training the target domain text generation model based on the above training data.
[0186] Baichuan-7B is selected as the target domain text generation model architecture, and the weight of Baichuan-7B is used as the initialization parameter. The pre-trained target domain text generation model includes an embedding layer, an encoding layer, and a language layer, using the Transformer architecture and an autoregressive self-attention mechanism. Specifically, it includes the following structure:
[0187] a. Embedding layer: The embedding layer consists of a word embedding layer and a position embedding layer. The word embedding layer receives a word sequence and outputs a word embedding vector sequence. The position embedding layer receives a position sequence and outputs a position vector sequence.
[0188] b. Encoding layer: It consists of multiple Transformer layers, with an autoregressive self-attention mechanism in the middle. The encoding layer receives a sequence of word embedding vectors and a sequence of position vectors, and outputs a sequence of semantic latent vectors.
[0189] c. Language layer: It consists of a fully connected layer, which accepts the semantic latent vector sequence output by the encoding layer. After calculation by the fully connected layer, the probability distribution of each word is calculated through the Softmax function.
[0190] The training target domain text generation model includes the following process:
[0191] Step 1: Process the training data to obtain a set of word sequences, which specifically includes:
[0192] i. Traverse the training data, serialize the teaching material unit information and annotation content respectively, and perform text splicing in the order of teaching material unit information start identifier, teaching material unit information serialization result, annotation content start identifier, and annotation content serialization result to obtain the training condition text.
[0193] ii. Use a word segmenter to segment and encode the training conditional text to obtain a conditional word sequence.<reserved_100> As the field text attribute start mark, select<reserved_101> As the start mark of the annotation content, the conditional text is encoded using Baichuan-7B to obtain the conditional word sequence.
[0194] iii. According to the conditional word sequence, construct a 0-marker sequence of the same length. That is, construct a 0-marker sequence of the same length as the conditional word sequence.
[0195] iv. Concatenate the text in the order of material text identifier, material text, and end identifier to obtain the generated text.<reserved_105> As a material text identifier and as an end identifier.
[0196] v. Use the word segmenter to segment and encode the generated text to obtain the generated word sequence.
[0197] vi. Construct a 1-marker sequence. Construct a 1-marker sequence of the same length based on the generated word sequence.
[0198] vii. Connect the conditional word sequence and the generated word sequence to obtain the input word sequence, and connect the 0 identifier sequence and the 1 identifier sequence to obtain the input identifier sequence.
[0199] viii. Shift the input word sequence to the left by one position to obtain the target word sequence.
[0200] ix. Add 1 identifier word to the end of the input identifier sequence, and also shift it to the left by 1 position to obtain the target identifier word sequence.
[0201] x. Repeat the above steps until all training data are encoded into input word sequence, target word sequence, and target identification word sequence.
[0202] Step 2: Use the gradient descent algorithm to train the target domain text generation model, which specifically includes the following process:
[0203] i. Perform batch sampling without replacement on the training set to obtain batch word sequence, batch target word sequence, and batch target identification word sequence.
[0204] ii. Input the batch word sequence into the target domain text generation model to obtain the probability distribution of the predicted words.
[0205] iii. Calculate the cross entropy loss between the probability distribution of the predicted word and the target sequence according to the following formula.
[0206]
[0207] p represents the probability distribution of the predicted word, y is the target word sequence, w is the batch target identification word sequence, and N is the batch target word sequence length. c and C are the current word and all the words in the vocabulary, respectively.
[0208] iv. Minimize the cross entropy loss through the optimizer, calculate the gradient of the estimated model and complete the weight update.
[0209] v. Repeat steps ad until all training data are sampled.
[0210] vi. Repeat steps ae until the preset number of rounds is reached and the training stops.
[0211] In terms of training, this example uses the method described in the method for training. In terms of training details, the following settings are made: For the optimizer, Adamw is selected, the learning rate is set to 3e-5, the weight decay coefficient is set to 0.01, β1 is 0.9, and β2 is 0.95. For the learning rate scheduling strategy, a linear decay strategy with preheating is selected, the decay coefficient is 0.1, and the preheating is 100 steps. In the embodiment of this application, a total of 2000 steps are trained, the batch size is set to 8, 4 cards A800 are selected for training, and zero-2 is selected for parallel mode.
[0212] The third stage: input the user's text generation requirements into the generation model to generate English listening materials.
[0213] Step 1: Get a whitelist of words. Decide on a list of words and make sure that only those words are used in the generated material.
[0214] The white-name words in the embodiment of the present application are obtained in the following manner: extract the words that appear in each unit from the People's Education Press textbook according to the organizational dimension of each unit as candidate words. Perform part-of-speech restoration on the candidate words to obtain a second candidate word. The candidate words and the second candidate words together constitute a white-name word list. Extract the words of each unit from the textbook, perform part-of-speech restoration, and obtain a word list to ensure that only these words are used in the generated materials.
[0215] Step 2: Provide textbook unit information and annotation content as generation conditions.
[0216] When the material is generated, the user is required to provide the teaching material unit information and annotation content. In this example, take the seventh grade first volume unit 5 as an example.
[0217] Step 3: Serialize the textbook unit information and annotation content to form conditional text, and encode it using a word segmenter to obtain a conditional word sequence.
[0218] In the embodiment of the present application, the conditional text is a combination of the teaching material unit information start identifier + teaching material unit information serialization result + annotation content start identifier + annotation content serialization result + material text identifier. The conditional word sequence is obtained by further encoding the previous text with a word segmenter.
[0219] Step 4: Initialize the decoding word sequence. The decoding sequence is empty when it starts to be generated.
[0220] Step 5: Use the trained target domain text generation model to predict the next word probability in the text generation process. The above conditional word is input into the trained target domain text generation model. The next word probability refers to the word probability represented by the semantic latent vector at the last position.
[0221] a: Input the conditional word sequence: Input the prepared conditional word sequence into the trained target domain text generation model.
[0222] b: Predicted word probability: The model predicts the next possible word based on the input conditional word sequence and calculates a probability value for each possible word. This probability reflects the model's belief that each word is the next word.
[0223] c: Sort words: Sort all possible words according to their probability values from high to low.
[0224] d: Select the highest probability word: Select the word with the highest probability as the next word to be predicted. In this example, assume that word number 10287 has the highest probability.
[0225] e: Add to the decoding sequence: Add the word with the highest probability to the decoding sequence. The decoding sequence may be empty at the beginning, and the sequence becomes
[10287] after adding.
[0226] Use the trained model to predict the next word and select the word with the highest probability. Input the conditional word sequence into the target domain text generation model to predict the probability of the next word. The next word probability refers to the word probability represented by the semantic latent vector at the last position. Sort the words from large to small according to the word probability, and add the current word with the highest probability to the decoded word sequence. In this way, the model can gradually build a coherent text sequence.
[0227] Step 6: Generate and filter: Decode the decoded word sequence to generate a temporary text. In this example, the decoded word sequence
[10287] is decoded to obtain the temporary text "have".
[0228] Before adding the predicted word to the decoding word sequence, it is necessary to check whether the word exists in the white list. If the word is on the white list, it means that it is a word that appears in the textbook and can be accepted and added to the decoding sequence. If the predicted word is not on the white list, that is, it is not a word in the textbook, then the word will not be added to the decoding sequence. This ensures that the generated text only contains words that students should be familiar with, thereby ensuring the accuracy of the material.
[0229] Step 7: Filter through the whitelist to ensure that all words are within the allowed range. Traverse the words in the temporary text to determine whether the word exists in the whitelist. If the current predicted word is not on the whitelist, remove the current word from the decoded word sequence, and the generation process will go back to the previous step to re-predict the next word until a word on the whitelist is found. If it exists, continue. For example, there is only the word have in the temporary text, and this word exists in the whitelist, so continue.
[0230] Step 8: Add the current word to the end of the conditional word sequence. For example, add
[10287] to the end of the conditional word sequence.
[0231] Step 9: By repeating the above steps, a complete text sequence is gradually constructed until the generated text meets all annotation conditions or reaches a predetermined length.
[0232] Repeat 5-8 for continuous iteration until the temporary text obtained by decoding the decoding word sequence meets the annotation condition, that is, the English listening material text is obtained. The temporary text obtained by decoding the decoding word sequence is the English listening material text.
[0233] This technology can generate English listening materials that meet the requirements, specifically, it can generate complete listening materials that do not exceed the syllabus and the number of words meets the range. In this process, a whitelist is used to ensure that the generated text only contains words that appear in the textbook, thereby ensuring the accuracy and applicability of the materials.
[0234] The above process can be applied in the system, where the receiving module receives the annotation content input by the user and passes it to the generating module. The generating module receives the annotation content input by the input module, generates the listening material that meets the requirements according to the above method, and outputs it to the output module; the output module receives the listening material text output by the generating module and returns it to the user through the HTTP protocol.
[0235] The embodiment of the present application provides a method for generating text in a target domain, by receiving a target domain text generation request sent by a user device, the target domain text generation request carries a subject parameter, a text type parameter, a word range and a domain text attribute; generating a target domain vocabulary according to the subject parameter and the text data set corresponding to the target domain; generating a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute; calling a target domain text generation model to obtain a decoding word sequence based on the conditional word sequence; using the word range and the target domain vocabulary to filter out a target decoding word sequence, and decoding it into a target domain text. Through the subject parameter and the text type parameter, the system can generate text related to a specific domain and type; by constructing a target domain vocabulary and a conditional word sequence, a structured information basis is provided for text generation. Using the word range and the target domain vocabulary to filter the decoding word sequence, the length and quality of the generated text are controlled to avoid content redundancy or deviation from the subject. By precisely controlling various aspects of the text, the end user can obtain more satisfactory and expected text content.
[0236] Based on the same technical concept, the present application embodiment also provides a target domain text generation system, such as Figure 3 As shown, the system comprises:
[0237] A request receiving module 301 is used to receive a target domain text generation request sent by a user device, wherein the target domain text generation request carries a subject parameter, a text type parameter, a word count range, and domain text attributes;
[0238] A target domain vocabulary module 302 is used to generate a target domain vocabulary according to the subject parameters and the text data set corresponding to the target domain;
[0239] A conditional word sequence module 303, used to generate a conditional word sequence according to the subject parameter, the text type parameter and the domain text attribute;
[0240] A decoding word sequence module 304 is used to call a target domain text generation model to obtain a decoding word sequence based on the conditional word sequence;
[0241] The target domain text generation module 305 is used to select a target decoding word sequence using the word count range and the target domain word list, and decode it into the target domain text.
[0242] The present application also provides an electronic device corresponding to the method provided in the above embodiment. Figure 4, which shows a schematic diagram of an electronic device provided by some embodiments of the present application. The electronic device 20 may include: a processor 200, a memory 201, a bus 202 and a communication interface 203, wherein the processor 200, the communication interface 203 and the memory 201 are connected via the bus 202; the memory 201 stores a computer program that can be run on the processor 200, and the processor 200 executes the method provided by any of the aforementioned embodiments of the present application when running the computer program.
[0243] The memory 201 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one physical port (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0244] The bus 202 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 201 is used to store programs, and the processor 200 executes the programs after receiving execution instructions. The method disclosed in any implementation of the aforementioned embodiment of the present application may be applied to the processor 200, or implemented by the processor 200.
[0245] The processor 200 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 200. The above processor 200 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a readily available programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 201, and the processor 200 reads the information in the memory 201 and completes the steps of the above method in combination with its hardware.
[0246] The electronic device provided in the embodiment of the present application and the method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, operated or implemented by them.
[0247] The present application also provides a computer-readable storage medium corresponding to the method provided in the above embodiment. Figure 5 The computer-readable storage medium shown is a CD 30 on which a computer program (ie, a program product) is stored. When the computer program is run by a processor, the method provided in any of the aforementioned embodiments is executed.
[0248] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0249] The computer-readable storage medium provided in the above-mentioned embodiments of the present application and the method provided in the embodiments of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, run or implemented by the application program stored therein.
[0250] It should be noted that the above embodiments illustrate the present application rather than limit the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets should not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present application may be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names.
[0251] The above is only a preferred specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
[0252] The above description is only a preferred embodiment of the present invention, and does not limit the patent scope of the present invention. All equivalent structural changes made by using the contents of the present invention specification and drawings under the concept of the present invention, or directly / indirectly applied in other related technical fields are included in the patent protection scope of the present invention.
Claims
1. A method for generating target domain text, characterized in that: The method comprises: Receive a target domain text generation request sent by a user device, the target domain text generation request carrying a topic parameter, a text type parameter, a word range, and a domain text attribute; the text type parameter includes parameters of a dialogue type, a statement type, and a role-playing type, and the domain text attribute represents language elements used in a set domain, including vocabulary, phrases, sentence patterns, and grammatical structures; According to the subject parameter, all words under the subject parameter are extracted from the text data set corresponding to the target domain as a first candidate word list; grammatical standardization is performed on the candidate words in the first candidate word list to obtain a second candidate word list; the first candidate word list and the second candidate word list are combined to obtain the target domain word list; Generate a conditional text according to the subject parameter, the text type parameter and the domain text attribute; encode the conditional text to obtain the conditional word sequence; Serializing the domain text attribute to obtain a domain text attribute processing result; serializing the subject parameter and the text type parameter to obtain an annotation content processing result; sequentially concatenating the start identifier of the domain text attribute, the domain text attribute processing result, the start identifiers of the subject parameter and the text type parameter, the annotation content processing result and the text identifier to be generated to obtain the conditional text; Calling the target domain text generation model to calculate the probability value set of the candidate word at the next sequence position in the conditional word sequence; sorting the probability values in the probability value set from large to small; adding the word with the largest probability value to the initialization word sequence to generate the decoding word sequence; Decode the decoding word sequence to obtain the corresponding decoding vocabulary; find out whether the decoding vocabulary exists in the target domain vocabulary; if not, delete the current word from the decoding word sequence, add the word corresponding to the next digit of the maximum value in the probability value sorting to the decoding word sequence, and continue to execute subsequent steps; if it exists, add the decoding vocabulary to the end of the conditional word sequence; repeat the above steps until the conditional word sequence meets the word number range, obtain the target decoding word sequence, and decode it into the target domain text.
2. The method according to claim 1, characterized in that The target domain text generation model is trained according to the following steps: Based on the training data set, an input word sequence, a target word sequence and a target identification word sequence are obtained by processing; Batch sampling the input word sequence, the target word sequence and the target identification word sequence to obtain a batch word sequence, a batch target word sequence and a batch target identification word sequence; Inputting the batch of word sequences into a pre-trained target domain text generation model to obtain a probability distribution of predicted words; Calculate the cross entropy loss between the probability distribution of the predicted word and the target word sequence; Calculate the gradient of the target domain text generation model and update the weights by minimizing the cross entropy loss; Repeat the above steps until the number of training rounds reaches the preset number, and then the training stops.
3. The method according to claim 2, characterized in that The training data set includes material text; the processing based on the training data set to obtain the input word sequence, the target word sequence and the target identification word sequence includes: Serializing and encoding the training data set to obtain a training conditional word sequence; Constructing a sequence of zero identifiers having the same length as the training conditional word sequence; The training generated text is obtained by sequentially splicing the start mark of the material text, the material text, and the end mark of the material text, and encoding is performed to obtain a training generated word sequence; Constructing a 1-identifier sequence having the same length as the training generated vocabulary sequence; The training conditional word sequence and the training generated word sequence are concatenated to obtain an input word sequence, and the 0 identification sequence and the 1 identification sequence are concatenated to obtain an input identification sequence; The input word sequence is shifted to the left by one word position to obtain a target word sequence; Adding 1 identification word at the end of the input identification sequence and shifting the word position to the left to obtain a target identification word sequence; Repeat the above steps until the training data set is processed into an input word sequence, a target word sequence, and a target identification word sequence.
4. The method according to claim 3, characterized in that The training data set also includes subject parameters, text type parameters and domain text attributes corresponding to the material text; the training data set is serialized and encoded to obtain a training conditional word sequence, including: Serializing the domain text attributes corresponding to the material text to obtain a training domain text attribute processing result; Serializing the subject parameters and text type parameters corresponding to the material text to obtain a training annotation content processing result; The starting identifier of the domain text attribute of the material text, the processing result of the training domain text attribute, the starting identifier of the subject parameter and the text type parameter of the material text, and the processing result of the training annotation content are sequentially spliced to obtain the training condition text; The training condition text is encoded to obtain the training condition word sequence.
5. A target domain text generation system, characterized in that: The system comprises: A request receiving module, configured to receive a target domain text generation request sent by a user device, wherein the target domain text generation request carries a subject parameter, a text type parameter, a word range, and a domain text attribute; the text type parameter includes parameters of a dialogue type, a statement type, and a role-playing type; and the domain text attribute represents language elements used in a set domain, including vocabulary, phrases, sentence patterns, and grammatical structures; A target domain vocabulary module is used to extract all words under the subject parameter from the text data set corresponding to the target domain according to the subject parameter as a first candidate word vocabulary; perform grammatical standardization on the candidate words in the first candidate word vocabulary respectively to obtain a second candidate word vocabulary; merge the first candidate word vocabulary and the second candidate word vocabulary to obtain the target domain vocabulary; A conditional word sequence module is used to generate a conditional text according to the subject parameter, the text type parameter and the domain text attribute; and encode the conditional text to obtain the conditional word sequence; The decoding word sequence module is used to serialize the domain text attributes to obtain the domain text attribute processing results; serialize the subject parameters and the text type parameters to obtain the annotation content processing results; sequentially splice the start identifier of the domain text attribute, the domain text attribute processing results, the start identifiers of the subject parameters and the text type parameters, the annotation content processing results and the text identifier to be generated to obtain the conditional text; call the target domain text generation model to calculate the probability value set of the candidate words at the next sequence position in the conditional word sequence; sort the probability values in the probability value set from large to small; add the word with the largest probability value to the initialization word sequence to generate the decoding word sequence; The target domain text generation module is used to decode the decoding word sequence to obtain the corresponding decoding vocabulary; find out whether the decoding vocabulary exists in the target domain vocabulary table, if not, delete the current word from the decoding word sequence, add the word corresponding to the next digit of the maximum value in the probability value sorting to the decoding word sequence, and continue to execute subsequent steps; if it exists, add the decoding vocabulary to the end of the conditional word sequence; repeat the above steps until the conditional word sequence meets the word number range, obtain the target decoding word sequence, and decode it into the target domain text.
