Copywriting generation method, device, equipment and storage medium
By extracting and combining key sentences from the original text data to generate training samples and train the copywriting generation model, it solves the problem of low efficiency of deep learning models in the field of big data and improves the accuracy and efficiency of copywriting generation.
Patent Information
- Application Number
- CN202210061762.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-19
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2042-01-19
AI Technical Summary
In areas with large data volumes such as news, it is difficult for existing deep learning models to improve efficiency while ensuring the accuracy of copywriting generation.
The key sentences are extracted from the original text data through the preset graph sorting algorithm to obtain a set of key sentences, which are combined with the real copy to form a text information pair, and then combined to generate a training sample set. These samples are then used to train the copywriting generation model to obtain a standard copywriting generation model. Finally, key sentences in the text to be processed are extracted and input into the standard copywriting generation model to generate standard copywriting.
This method can improve the efficiency of copywriting generation, reduce the length of text input to the model, and increase the speed of model training while ensuring the accuracy of copywriting.
Smart Images

Figure CN114386392B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a copywriting generation method, device, electronic device and computer-readable storage medium. Background Art
[0002] With the rapid development of the Internet advertising market, the amount of advertising produced has also increased rapidly. Traditional manually produced advertisements have gradually been unable to meet the massive amount of information flow added every day. Therefore, machine-automated copy generation is particularly important.
[0003] Existing copywriting generation methods usually use deep learning models. However, for complex deep learning models, their training time and convergence speed are important factors that must be considered. In many fields, such as the news field, the amount of relevant data is large, and the deep learning model cannot meet the requirements of copywriting accuracy while ensuring efficiency. Therefore, it is urgent to propose a method to ensure the accuracy of copywriting while improving the efficiency of copywriting generation. Summary of the invention
[0004] The present invention provides a copywriting generation method, device and computer-readable storage medium, the main purpose of which is to ensure the accuracy of the copywriting while improving the efficiency of copywriting generation.
[0005] To achieve the above object, the present invention provides a method for generating a copy, comprising:
[0006] Obtaining an original text data set, and extracting key sentences from a plurality of original text data in the original text data set based on a preset graph sorting algorithm to obtain a plurality of key sentence sets;
[0007] Combining a plurality of the key sentence sets and a plurality of preset real texts corresponding to the original text data into a plurality of text information pairs, and combining the plurality of the text information pairs to obtain a training sample set;
[0008] Using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model;
[0009] The text to be processed is obtained, key sentences in the text to be processed are extracted, and the key sentences are input into the standard copy generation model to obtain the standard copy corresponding to the text to be processed.
[0010] Optionally, the using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model includes:
[0011] Performing vectorization processing on the training sample set to obtain an embedding vector set;
[0012] The embedding vectors in the embedding vector set and the preset position vector are summed to obtain a standard vector set;
[0013] Inputting the standard vector set into a plurality of stacked transformer modules in the copy generation model to generate copy, thereby obtaining a predicted copy;
[0014] The copy generation model is optimized by comparing the predicted copy with the preset real copy to see whether they are consistent, so as to obtain a standard copy generation model.
[0015] Optionally, the step of inputting the standard vector set into a plurality of stacked transformer modules in the copywriting generation model to generate copywriting to obtain a predicted copywriting includes:
[0016] Using a first transformer module among the plurality of stacked transformer modules to perform self-attention processing on the standard vector, and passing the result after the self-attention processing to a neural network layer to obtain a first result vector;
[0017] Performing vector processing on the first result vector as an input of a second transformer module in the plurality of stacked transformer modules, and repeatedly performing the vector processing until all operations on the stacked transformer modules are completed, thereby obtaining a stacked output;
[0018] The stacked output is multiplied by the embedding matrix to obtain an attention score, and a predicted text is obtained according to the size of the attention score.
[0019] Optionally, the preset graph sorting algorithm is used to extract key sentences from the multiple original text data in the original text data set to obtain multiple key sentence sets, including:
[0020] Performing word segmentation screening on the plurality of original text data to obtain a standard word segmentation set;
[0021] Constructing a directed weighted graph according to the standard participles in the standard participle set, and calculating weights of multiple nodes in the directed weighted graph;
[0022] Summarize the nodes in the directed weighted graph whose weights exceed a preset threshold as target keywords to obtain key word segments of the original text data set;
[0023] The original texts corresponding to the key participles are selected as key sentences for aggregation to obtain a key sentence set.
[0024] Optionally, the performing word segmentation screening on the plurality of original text data to obtain a standard word segmentation set includes:
[0025] Segmenting the plurality of original text data into sentences according to preset symbols to obtain an original sentence set;
[0026] Deleting the stop words in the original sentence set, and performing word segmentation processing on the original sentences after deleting the stop words to obtain an initial word segmentation set;
[0027] Part-of-speech tagging is performed on multiple initial participles in the initial participle set, and initial participles that are consistent with a preset designated part-of-speech are retained as standard participles to obtain a standard participle set.
[0028] Optionally, calculating the weights of a plurality of nodes in the directed weighted graph includes:
[0029] The weights of multiple nodes in the directed weighted graph are calculated using the following calculation formula:
[0030]
[0031] Among them, WS(V i ) represents node V i The weight of d is the damping coefficient, In(V i ) points to node V i The first node set, Out(V j ) is the node V i The second node set pointed to, W ji For node V i and V j The connection weight between jk For node V k and V j The connection weight between .
[0032] Optionally, the combining and processing of a plurality of the text information pairs to obtain a training sample set includes:
[0033] Obtain a preset first identifier and a second identifier;
[0034] Using the second identifier, connecting the key sentence set in the text information pair and the preset real copy to obtain connected text data;
[0035] The first identifier is added before the connection text data, and the second identifier is added after the connection text data to obtain a training sample set.
[0036] In order to solve the above problems, the present invention further provides a copywriting generation device, the device comprising:
[0037] A key sentence extraction module is used to obtain an original text data set, and extract key sentences from multiple original text data in the original text data set based on a preset graph sorting algorithm to obtain multiple key sentence sets;
[0038] A sample set generation module, used to form a plurality of text information pairs from a plurality of the key sentence sets and a plurality of preset real texts corresponding to the original text data, and to combine the plurality of the text information pairs to obtain a training sample set;
[0039] A model training module, used to train a preset copywriting generation model using the training sample set to obtain a standard copywriting generation model;
[0040] The copywriting generation module is used to obtain the text to be processed, extract the key sentences in the text to be processed, and input the key sentences into the standard copywriting generation model to obtain the standard copywriting corresponding to the text to be processed.
[0041] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0042] at least one processor; and,
[0043] a memory communicatively connected to the at least one processor; wherein,
[0044] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the above-mentioned text generation method.
[0045] In order to solve the above problem, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the above-mentioned text generation method.
[0046] The embodiment of the present invention uses a preset graph sorting algorithm to extract key sentences from multiple original text data in the original text data set, and obtains multiple key sentence sets. Since the key sentences retain the main idea of the original text data and reduce the length of the text input to the subsequent model, the model accuracy can be guaranteed while improving the speed of model training. Multiple key sentence sets and preset real texts corresponding to multiple original text data sets are combined to form multiple text information pairs, and the multiple text information pairs are combined and processed to obtain a training sample set. The text generation model is trained using the training sample set to obtain a standard text generation model. The text key sentences in the text to be processed are extracted, and the text key sentences are input into the standard text generation model to obtain a standard text. Therefore, the text generation method, device, electronic device and computer-readable storage medium proposed in the present invention can achieve the purpose of ensuring the accuracy of the text while improving the efficiency of model generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A schematic diagram of a process for generating a text document according to an embodiment of the present invention;
[0048] Figure 2 A functional module diagram of a document generation device provided by an embodiment of the present invention;
[0049] Figure 3 A schematic diagram of the structure of an electronic device for implementing the text generation method provided by an embodiment of the present invention.
[0050] 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
[0051] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0052] The embodiment of the present application provides a method for generating a copy. The execution subject of the copy generation method includes but is not limited to at least one of the electronic devices such as a server, a terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the copy generation method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0053] Reference Figure 1 , which is a flow chart of a method for generating text provided by an embodiment of the present invention.
[0054] In this embodiment, the copywriting generation method includes:
[0055] S1. Obtain an original text data set, and extract key sentences from multiple original text data in the original text data set based on a preset graph sorting algorithm to obtain multiple key sentence sets.
[0056] In the embodiment of the present invention, the original text data set refers to text information in different fields, for example, news information text in the news field. The original text data can be crawled from a public website or an existing database.
[0057] Specifically, the preset graph sorting algorithm extracts key sentences from the multiple original text data in the original text data set respectively to obtain multiple key sentence sets, including:
[0058] Performing word segmentation screening on the plurality of original text data to obtain a standard word segmentation set;
[0059] Constructing a directed weighted graph according to the standard participles in the standard participle set, and calculating the weights of multiple nodes in the directed weighted graph;
[0060] Summarize the nodes in the directed weighted graph whose weights exceed a preset threshold as target keywords to obtain key word segments of the original text data set;
[0061] The original texts corresponding to the key participles are selected as key sentences for aggregation to obtain a key sentence set.
[0062] Preferably, the graph sorting algorithm can be a TextRank model, which can extract key sentences from the text. This model extracts sentences quickly and can quickly process a large amount of text. The purpose of compressing the original text information is achieved by extracting key sentences, and a training sample is constructed.
[0063] Among them, the TextRank model is a graph-based ranking model for text. Its basic idea is to divide the text into several components (words, sentences) and establish a graph model. The graph model is essentially a directed weighted graph.
[0064] For example, after the original text data X is segmented into sentences, there are N sentences, and the obtained set of key sentences is X = [Xi1, Xi2, Xi3, …, XiN]. After key sentence extraction, the set Xi has M (M < N) sentences, and the new set is Xinew = [Xi1, Xi2, Xi3, …, XiM]. By this method, the original text information is compressed, and the new sample becomes (Xinew, Yi).
[0065] Further, the tokenization and screening of the multiple original text data to obtain a standard token set includes:
[0066] Performing sentence segmentation on the multiple original text data according to a preset symbol to obtain an original sentence set;
[0067] Deleting stop words in the original sentence set and performing tokenization on the original sentences after deleting stop words to obtain an initial token set;
[0068] Performing part-of-speech tagging on multiple initial tokens in the initial token set, and retaining the initial tokens that are consistent with a preset specified part of speech as standard tokens to obtain a standard token set.
[0069] Specifically, the preset symbol can be a full stop, and the deletion of stop words in the original sentence set can be performed by comparing with an existing stop word list for deletion. The tokenization process can use a trained tokenization model or a baseline tokenizer, and the preset specified part of speech can be nouns, verbs, and adjectives.
[0070] Specifically, the calculation of the weights of multiple nodes in the directed weighted graph includes:
[0071] Calculating the weights of multiple nodes in the directed weighted graph using the following calculation formula:
[0072]
[0073] where WS(V i ) represents the weight of node V i , d is the damping coefficient, In(V i ) is the first set of nodes pointing to node V i , Out(V j ) is the second set of nodes pointed to by node V i , W ji is the connection weight between node V i and V j , and W jk is the connection weight between node V k and V j .
[0074] The damping coefficient d represents the probability of pointing from a specific point in the directed weighted graph to any other point. Preferably, the damping coefficient is 0.85.
[0075] S2. Combining the plurality of key sentence sets and the plurality of preset real texts corresponding to the original text data into a plurality of text information pairs, and combining the plurality of text information pairs to obtain a training sample set.
[0076] In the embodiment of the present invention, the preset real text corresponding to the original text data refers to the text summarized according to the original text data, and the key sentence set and the preset real text are combined to obtain a text information pair.
[0077] For example, the plurality of text information pairs are [(X1 new1 , Y1 1 ), (X2 new2 , Y2 2 ),…,(Xi new2 , Yi 2 ),…,(XN new2 , YN * )], where Y1 1 , Y2 2 …Yi 2 …YN * The preset real text corresponding to the original text data.
[0078] Specifically, the combining and processing of the plurality of text information pairs to obtain a training sample set includes:
[0079] Obtain a preset first identifier and a second identifier;
[0080] Using the second identifier, connecting the key sentence set in the text information pair and the preset real copy to obtain connected text data;
[0081] The first identifier is added before the connection text data, and the second identifier is added after the connection text data to obtain a training sample set.
[0082] In detail, the first identifier is the start identifier [CLS], the second identifier is the separator [SEP], and if the text information pair is (X', Y'), a training sample is generated by connecting the special identifiers [CLS] and [SEP]: [CLS]X'[SEP]Y'[SEP].
[0083] S3. Using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model.
[0084] In the embodiment of the present invention, the preset copywriting generation model is the GPT-2 model. The text generated by the GPT-2 model has good coherence and expression, and its stable and excellent performance has attracted widespread attention in the industry. This model is based on the transformer feature extractor and uses a stacking method to consume a lot of computing power for learning and training on massive texts.
[0085] The GPT-2 model is constructed by stacking multiple transformer feature extractors, that is, connecting the multiple transformer feature extractors in series. The training sample set is input to the first transformer feature extractor among the multiple transformer feature extractors, and the output of the first transformer feature extractor is used as the input of the second transformer feature extractor among the multiple transformer feature extractors, and so on.
[0086] Specifically, the method of using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model includes:
[0087] Performing vectorization processing on the training sample set to obtain an embedding vector set;
[0088] The embedding vectors in the embedding vector set and the preset position vector are summed to obtain a standard vector set;
[0089] Inputting the standard vector set into a plurality of stacked transformer modules in the copy generation model to generate copy, thereby obtaining a predicted copy;
[0090] The copy generation model is optimized by comparing the predicted copy with the preset real copy to see whether they are consistent, so as to obtain a standard copy generation model.
[0091] In detail, the vectorization process is to find the embedding vector corresponding to the training sample in the embedding matrix, wherein each row in the embedding matrix is a word embedding vector.
[0092] Furthermore, the step of inputting the standard vector set into a plurality of stacked transformer modules in the copywriting generation model to generate copywriting to obtain a predicted copywriting includes:
[0093] Using a first transformer module among the plurality of stacked transformer modules to perform self-attention processing on the standard vector, and passing the result after the self-attention processing to a neural network layer to obtain a first result vector;
[0094] Performing vector processing on the first result vector as an input of a second transformer module in the plurality of stacked transformer modules, and repeatedly performing the vector processing until all operations on the stacked transformer modules are completed, thereby obtaining a stacked output;
[0095] The stacked output is multiplied by the embedding matrix to obtain an attention score, and a predicted text is obtained according to the size of the attention score.
[0096] In detail, in the GPT-2 model used in this scheme, the transformer stacking layer is 12 and the text length is set to 800, which is a relatively small-scale model.
[0097] S4. Obtain the text to be processed, extract key sentences in the text to be processed, and input the key sentences into the standard copy generation model to obtain the standard copy corresponding to the text to be processed.
[0098] In an embodiment of the present invention, the text to be processed is initial text data for which copywriting needs to be generated, and a key sentence extraction model is used to extract key sentences from the text to be processed, wherein the key sentence extraction model can be a TextRank model, and the key sentences of the text are input into the standard copywriting generation model to obtain a standard copywriting.
[0099] The embodiment of the present invention uses a preset graph sorting algorithm to extract key sentences from multiple original text data in the original text data set, and obtains multiple key sentence sets. Since the key sentences retain the main idea of the original text data and reduce the length of the text input to the subsequent model, the model accuracy can be guaranteed while improving the speed of model training. Multiple key sentence sets and preset real texts corresponding to multiple original text data sets are combined to form multiple text information pairs, and the multiple text information pairs are combined and processed to obtain a training sample set. The training sample set is used to train the text generation model to obtain a standard text generation model. The text key sentences in the text to be processed are extracted, and the text key sentences are input into the standard text generation model to obtain a standard text. Therefore, the text generation method proposed in the present invention can achieve the purpose of ensuring the accuracy of the text while improving the efficiency of model generation.
[0100] like Figure 2 , which is a functional module diagram of a text generation device provided by an embodiment of the present invention.
[0101] The text generation device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the text generation device 100 can include a key sentence extraction module 101, a sample set generation module 102, a model training module 103 and a text generation module 104. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0102] In this embodiment, the functions of each module / unit are as follows:
[0103] The key sentence extraction module 101 is used to obtain an original text data set, and extract key sentences from multiple original text data in the original text data set based on a preset graph sorting algorithm to obtain multiple key sentence sets;
[0104] The sample set generation module 102 is used to form a plurality of text information pairs from the plurality of key sentence sets and the plurality of preset real texts corresponding to the original text data, and to combine the plurality of text information pairs to obtain a training sample set;
[0105] The model training module 103 is used to train a preset copywriting generation model using the training sample set to obtain a standard copywriting generation model;
[0106] The text generation module 104 is used to obtain the text to be processed, extract the key sentences in the text to be processed, and input the key sentences into the standard text generation model to obtain the standard text corresponding to the text to be processed.
[0107] In detail, the specific implementation of each module of the copywriting generation device 100 is as follows:
[0108] Step 1: obtain an original text data set, and extract key sentences from multiple original text data in the original text data set based on a preset graph sorting algorithm to obtain multiple key sentence sets.
[0109] In the embodiment of the present invention, the original text data set refers to text information in different fields, for example, news information text in the news field. The original text data can be crawled from a public website or an existing database.
[0110] Specifically, the preset graph sorting algorithm extracts key sentences from the multiple original text data in the original text data set respectively to obtain multiple key sentence sets, including:
[0111] Performing word segmentation screening on the plurality of original text data to obtain a standard word segmentation set;
[0112] Construct a directed weighted graph based on the standard word segmentation in the standard word segmentation set, and calculate the weights of multiple nodes in the directed weighted graph;
[0113] Summarize the nodes in the directed weighted graph whose weights exceed the preset threshold as target keywords to obtain the key word segmentation of the original text dataset;
[0114] Select the original text corresponding to the key word segmentation as key sentences for summarization to obtain a set of key sentences.
[0115] Preferably, the graph sorting algorithm can be the TextRank model. The TextRank model can extract key sentences in the text. This model extracts sentences quickly and can process a large amount of text quickly. By extracting key sentences, the purpose of compressing the original text information is achieved to construct training samples.
[0116] Among them, the TextRank model is a graph-based sorting model for text. Its basic idea is to segment the text into several constituent units (words, sentences) and establish a graph model. The graph model is essentially a directed weighted graph.
[0117] For example, after the original text data X is segmented into sentences, there are N sentences, and the obtained set of key sentences is X = [Xi1, Xi2, Xi3,..., XiN]. After extracting key sentences, the Xi set has M (M < N) sentences, and the new set is Xinew = [Xi1, Xi2, Xi3,..., XiM]. By this method, the original text information is compressed, and the new sample becomes (Xinew, Yi).
[0118] Furthermore, the screening of word segmentation for multiple original text data to obtain a standard word segmentation set includes:
[0119] Segment multiple original text data according to preset symbols to obtain an original sentence set;
[0120] Delete the stop words in the original sentence set, and perform word segmentation on the original sentences after deleting the stop words to obtain an initial word segmentation set;
[0121] Perform part-of-speech tagging on multiple initial word segmentations in the initial word segmentation set, and retain the initial word segmentations that are consistent with the preset specified part of speech as standard word segmentations to obtain a standard word segmentation set.
[0122] Specifically, the preset symbol can be a full stop. Deleting the stop words in the original sentence set can be compared with the existing stop word list for deletion. The word segmentation process can use a trained word segmentation model or a benchmark word segmenter. The preset specified part of speech can be nouns, verbs, and adjectives.
[0123] Specifically, calculating the weights of multiple nodes in the directed weighted graph includes:
[0124] The weights of multiple nodes in the directed weighted graph are calculated using the following calculation formula:
[0125]
[0126] Among them, WS(V i ) represents the node V i The weight of d is the damping coefficient, In(V i ) points to node V i The first node set, Out(V j ) is the node V i The second node set pointed to, W ji For node V i and V j The connection weight between jk For node V k and V j The connection weight between .
[0127] The damping coefficient d represents the probability of pointing from a specific point in the directed weighted graph to any other point. Preferably, the damping coefficient is 0.85.
[0128] Step 2: Combining multiple sets of key sentences and multiple preset real texts corresponding to the original text data into multiple text information pairs, and combining the multiple text information pairs to obtain a training sample set.
[0129] In the embodiment of the present invention, the preset real text corresponding to the original text data refers to the text summarized according to the original text data, and the key sentence set and the preset real text are combined to obtain a text information pair.
[0130] For example, the plurality of text information pairs are [(X1 new1 , Y1 1 ), (X2 new2 , Y2 2 ),…,(Xi new2 , Yi 2 ),…,(XN new2 , YN * )], where Y1 1 , Y2 2 …Yi 2 …YN * The preset real text corresponding to the original text data.
[0131] Specifically, the combining and processing of the plurality of text information pairs to obtain a training sample set includes:
[0132] Obtain a preset first identifier and a second identifier;
[0133] Using the second identifier, connecting the key sentence set in the text information pair and the preset real copy to obtain connected text data;
[0134] The first identifier is added before the connection text data, and the second identifier is added after the connection text data to obtain a training sample set.
[0135] In detail, the first identifier is the start identifier [CLS], the second identifier is the separator [SEP], and if the text information pair is (X', Y'), a training sample is generated by connecting the special identifiers [CLS] and [SEP]: [CLS]X'[SEP]Y'[SEP].
[0136] Step three: Use the training sample set to train the preset copy generation model to obtain a standard copy generation model.
[0137] In the embodiment of the present invention, the preset copywriting generation model is the GPT-2 model. The text generated by the GPT-2 model has good coherence and expression, and its stable and excellent performance has attracted widespread attention in the industry. This model is based on the transformer feature extractor and uses a stacking method to consume a lot of computing power for learning and training on massive texts.
[0138] The GPT-2 model is constructed by stacking multiple transformer feature extractors, that is, connecting the multiple transformer feature extractors in series. The training sample set is input to the first transformer feature extractor among the multiple transformer feature extractors, and the output of the first transformer feature extractor is used as the input of the second transformer feature extractor among the multiple transformer feature extractors, and so on.
[0139] Specifically, the method of using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model includes:
[0140] Performing vectorization processing on the training sample set to obtain an embedding vector set;
[0141] The embedding vectors in the embedding vector set and the preset position vector are summed to obtain a standard vector set;
[0142] Inputting the standard vector set into a plurality of stacked transformer modules in the copy generation model to generate copy, thereby obtaining a predicted copy;
[0143] The copy generation model is optimized by comparing the predicted copy with the preset real copy to see whether they are consistent, so as to obtain a standard copy generation model.
[0144] In detail, the vectorization process is to find the embedding vector corresponding to the training sample in the embedding matrix, wherein each row in the embedding matrix is a word embedding vector.
[0145] Furthermore, the step of inputting the standard vector set into a plurality of stacked transformer modules in the copywriting generation model to generate copywriting to obtain a predicted copywriting includes:
[0146] Using a first transformer module among the plurality of stacked transformer modules to perform self-attention processing on the standard vector, and passing the result after the self-attention processing to a neural network layer to obtain a first result vector;
[0147] Performing vector processing on the first result vector as an input of a second transformer module in the plurality of stacked transformer modules, and repeatedly performing the vector processing until all operations on the stacked transformer modules are completed, thereby obtaining a stacked output;
[0148] The stacked output is multiplied by the embedding matrix to obtain an attention score, and a predicted text is obtained according to the size of the attention score.
[0149] In detail, in the GPT-2 model used in this scheme, the transformer stacking layer is 12 and the text length is set to 800, which is a relatively small-scale model.
[0150] Step 4: Obtain the text to be processed, extract key sentences in the text to be processed, and input the key sentences into the standard copy generation model to obtain the standard copy corresponding to the text to be processed.
[0151] In an embodiment of the present invention, the text to be processed is initial text data for which copywriting needs to be generated, and a key sentence extraction model is used to extract key sentences from the text to be processed, wherein the key sentence extraction model can be a TextRank model, and the key sentences of the text are input into the standard copywriting generation model to obtain a standard copywriting.
[0152] The embodiment of the present invention uses a preset graph sorting algorithm to extract key sentences from multiple original text data in the original text data set, and obtains multiple key sentence sets. Since the key sentences retain the main idea of the original text data and reduce the length of the text input to the subsequent model, the model accuracy can be guaranteed while improving the speed of model training. Multiple key sentence sets and preset real texts corresponding to multiple original text data sets are combined to form multiple text information pairs, and the multiple text information pairs are combined and processed to obtain a training sample set. The training sample set is used to train the text generation model to obtain a standard text generation model. The text key sentences in the text to be processed are extracted, and the text key sentences are input into the standard text generation model to obtain a standard text. Therefore, the text generation device proposed by the present invention can achieve the purpose of ensuring the accuracy of the text while improving the efficiency of model generation.
[0153] like Figure 3 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing a method for generating text provided by an embodiment of the present invention.
[0154] The electronic device 1 may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a document generation program.
[0155] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing a copywriting generation program, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.
[0156] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 may not only be used to store application software and various types of data installed in the electronic device, such as the code of a copywriting generation program, but may also be used to temporarily store data that has been output or is to be output.
[0157] The communication bus 12 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0158] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0159] Figure 3 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 3The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0160] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0161] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0162] The text generation program stored in the memory 11 of the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0163] Obtaining an original text data set, and extracting key sentences from a plurality of original text data in the original text data set based on a preset graph sorting algorithm to obtain a plurality of key sentence sets;
[0164] Combining a plurality of the key sentence sets and a plurality of preset real texts corresponding to the original text data into a plurality of text information pairs, and combining the plurality of the text information pairs to obtain a training sample set;
[0165] Using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model;
[0166] The text to be processed is obtained, key sentences in the text to be processed are extracted, and the key sentences are input into the standard copy generation model to obtain the standard copy corresponding to the text to be processed.
[0167] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.
[0168] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0169] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:
[0170] Obtaining an original text data set, and extracting key sentences from a plurality of original text data in the original text data set based on a preset graph sorting algorithm to obtain a plurality of key sentence sets;
[0171] Combining a plurality of the key sentence sets and a plurality of preset real texts corresponding to the original text data into a plurality of text information pairs, and combining the plurality of the text information pairs to obtain a training sample set;
[0172] Using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model;
[0173] The text to be processed is obtained, key sentences in the text to be processed are extracted, and the key sentences are input into the standard copy generation model to obtain the standard copy corresponding to the text to be processed.
[0174] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0175] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0176] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0177] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0178] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0179] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0180] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0181] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0182] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A copywriting generation method, characterized in that: The method comprises: Obtaining an original text data set, and extracting key sentences from a plurality of original text data in the original text data set based on a preset graph sorting algorithm to obtain a plurality of key sentence sets; Combining a plurality of the key sentence sets and a plurality of preset real texts corresponding to the original text data into a plurality of text information pairs, and combining the plurality of the text information pairs to obtain a training sample set; Using the training sample set to train a preset copywriting generation model to obtain a standard copywriting generation model; Acquire a text to be processed, extract key sentences from the text to be processed, and input the key sentences into the standard copy generation model to obtain a standard copy corresponding to the text to be processed; The method of using the training sample set to train the preset copy generation model to obtain a standard copy generation model includes: vectorizing the training sample set to obtain an embedding vector set; summing the embedding vectors in the embedding vector set and the preset position vector to obtain a standard vector set; inputting the standard vector set into a plurality of stacked transformer modules in the copy generation model to generate copy to obtain a predicted copy; optimizing the copy generation model by comparing whether the predicted copy is consistent with the preset real copy to obtain a standard copy generation model; The method extracts key sentences from multiple original text data in the original text data set based on a preset graph sorting algorithm to obtain multiple key sentence sets, including: performing word segmentation screening on multiple original text data to obtain a standard word segmentation set; constructing a directed weighted graph according to the standard word segmentations in the standard word segmentation set, and calculating the weights of multiple nodes in the directed weighted graph; aggregating the nodes in the directed weighted graph whose weights exceed a preset threshold as target keywords to obtain the key word segmentations of the original text data set; selecting the original text corresponding to the key word segmentation as a key sentence to aggregating to obtain the key sentence set; The combining and processing of the plurality of text information pairs to obtain a training sample set includes: obtaining a preset first identifier and a second identifier; using the second identifier to connect the key sentence set in the text information pair and the preset real text to obtain connected text data; adding the first identifier in front of the connected text data and adding the second identifier after the connected text data to obtain a training sample set.
2. The method for generating a copywriting according to claim 1, wherein: The step of inputting the standard vector set into a plurality of stacked transformer modules in the copywriting generation model to generate a copywriting to obtain a predicted copywriting includes: Using a first transformer module among the plurality of stacked transformer modules to perform self-attention processing on the standard vector, and passing the result after the self-attention processing to a neural network layer to obtain a first result vector; Performing vector processing on the first result vector as an input of a second transformer module in the plurality of stacked transformer modules, and repeatedly performing the vector processing until all operations on the stacked transformer modules are completed to obtain a stacked output; The stacked output is multiplied by the embedding vector set to obtain an attention score, and a predicted text is obtained according to the size of the attention score.
3. The method for generating a copywriting according to claim 1, wherein: The word segmentation screening of the plurality of original text data to obtain a standard word segmentation set includes: Segmenting the plurality of original text data into sentences according to preset symbols to obtain an original sentence set; Deleting the stop words in the original sentence set, and performing word segmentation processing on the original sentences after deleting the stop words to obtain an initial word segmentation set; Part-of-speech tagging is performed on multiple initial participles in the initial participle set, and initial participles that are consistent with a preset designated part-of-speech are retained as standard participles to obtain a standard participle set.
4. The method for generating a copywriting according to claim 1, wherein: The calculating weights of the plurality of nodes in the directed weighted graph comprises: The weights of multiple nodes in the directed weighted graph are calculated using the following calculation formula: in, Representation Node The weight of , d is the damping coefficient, Point to the node The first node set of For Node The second node set pointed to, For Node and The connection weights between For Node and The connection weight between .
5. A document generation device, used to implement the document generation method according to any one of claims 1 to 4, characterized in that: The device comprises: A key sentence extraction module is used to obtain an original text data set, and extract key sentences from multiple original text data in the original text data set based on a preset graph sorting algorithm to obtain multiple key sentence sets; A sample set generation module, used to form a plurality of text information pairs from a plurality of the key sentence sets and a plurality of preset real texts corresponding to the original text data, and to combine the plurality of the text information pairs to obtain a training sample set; A model training module, used to train a preset copywriting generation model using the training sample set to obtain a standard copywriting generation model; The copywriting generation module is used to obtain the text to be processed, extract the key sentences in the text to be processed, and input the key sentences into the standard copywriting generation model to obtain the standard copywriting corresponding to the text to be processed.
6. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text generation method according to any one of claims 1 to 4.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the document generation method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Text generation method for performing generative abstract extraction by combining semantics and text structure
CN111178053A
Text information processing method and device, electronic equipment and electronic system
CN112118359A