Method, apparatus, device and computer readable medium for generating text
By combining a Long Short-Term Memory network and a bidirectional LSTM with a pre-defined attention model, and by using contextual information and similar sentences to refine vocabulary, the problem of poor logical consistency in generated text in existing technologies is solved, thereby improving the efficiency and quality of text editing.
Patent Information
- Application Number
- CN201910668488.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-07-23
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2039-07-23
AI Technical Summary
The existing technology for automatically generating text based on keywords has poor logic, resulting in low efficiency in text editing.
The input semantics of sentences are encoded and decoded using a Long Short-Term Memory (LSTM) network. Combined with a bidirectional LSTM and a pre-defined attention model, the semantic vectors of the sentences above and below the sentences and the pre-defined vocabulary vectors are used to filter and refine words through similar sentences, thereby improving the logic and coherence of the text.
By comprehensively utilizing contextual information, the logic and editing efficiency of the text can be enhanced, and the richness and coherence of the vocabulary can be improved.
Smart Images

Figure CN112364657B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and in particular, to a method, device and computer readable medium for generating text. BACKGROUND
[0002] Automatic generation of text from keywords is applied in many technical fields, which can greatly reduce the time of manually editing text and improve the efficiency of editing text.
[0003] In the process of realizing the present application, the inventor found that the logic of automatically generating text from keywords in the prior art is poor, thereby reducing the efficiency of editing text. SUMMARY
[0004] Therefore, the embodiments of the present application provide a method, device and computer readable medium for generating text, which can improve the logic of generating text and improve the efficiency of editing text.
[0005] To achieve the above object, according to one aspect of the embodiments of the present application, a method for generating text is provided, comprising:
[0006] generating text according to keywords, wherein the text comprises one or more sentences;
[0007] encoding input semantics of the sentence by using a long short-term memory network according to semantic vectors of previous and subsequent sentences of the sentence and a semantic vector of the sentence;
[0008] decoding the input semantics of the sentence by using the long short-term memory network to obtain an updated sentence.
[0009] The encoding input semantics of the sentence by using a long short-term memory network according to semantic vectors of previous and subsequent sentences of the sentence and a semantic vector of the sentence comprises:
[0010] encoding input semantics of the sentence by using a long short-term memory network according to semantic vectors of previous and subsequent sentences of the sentence, a semantic vector of the sentence and a preset vocabulary vector of the sentence.
[0011] The method further comprises:
[0012] selecting similar sentences of the sentence according to the sentence and the keywords corresponding to the sentence;
[0013] selecting words in the sentence to form a first word library of the sentence according to a word frequency-inverse document frequency order, and selecting words in the similar sentence to form a second word library of the sentence according to the word frequency-inverse document frequency order;
[0014] screening, in the second word library, words not in the first word library according to the word frequency-inverse document frequency from high to low, and taking the first Y screened words as polishing words of the sentence, Y being a preset value greater than or equal to 1;
[0015] encoding the polishing words of the sentence and the keywords corresponding to the sentence to obtain a preset word library vector of the sentence.
[0016] The selecting words in the sentence to form a first word library of the sentence and selecting words in the similar sentence to form a second word library of the sentence comprises:
[0017] selecting nouns, adjectives and verbs in the sentence to form the first word library of the sentence;
[0018] selecting nouns, adjectives and verbs in the similar sentence to form the second word library of the sentence.
[0019] The selecting, according to the sentence and the keywords corresponding to the sentence, of the similar sentence of the sentence comprises:
[0020] retrieving, according to the sentence and the keywords corresponding to the sentence, the first 20 related sentences in a preset text library;
[0021] calculating Jaccard similarity of the sentence and the related sentences, and selecting the related sentence with the Jaccard similarity between 0.3 and 0.7 as the similar sentence.
[0022] The generating text according to keywords comprises:
[0023] converting the keywords of the next sentence and the generated current sentence into vectors, and encoding based on a long short-term memory network to obtain input semantics of the next sentence;
[0024] determining a hidden state of the next sentence according to the input semantics of the next sentence, an output word in the generated current sentence and a hidden state of the generated current sentence;
[0025] decoding to obtain the next sentence through the hidden state of the next sentence and the vector of the keywords of the next sentence;
[0026] generating the text from the generated current sentence and the next sentence.
[0027] The method further comprises:
[0028] updating one or more sentences in the text sentence by sentence to generate a text comprising all updated sentences.
[0029] The method further comprises:
[0030] The sentence is encoded by a bidirectional long short-term memory network, and then a preset attention model is used to obtain a semantic vector of the sentence.
[0031] The method further comprises:
[0032] The m sentences included in the context of the sentence and the m sentences included in the context of the sentence are encoded by a bidirectional long short-term memory network to obtain bidirectional semantic information, m being a positive integer.
[0033] The preset attention model is used to obtain semantic vectors of the sentences before and after the sentence in combination with the bidirectional semantic information.
[0034] According to a second aspect of the embodiment of the present application, a device for generating a text is provided, comprising:
[0035] a generating module configured to generate a text according to a keyword, the text comprising one or more sentences;
[0036] an encoding module configured to encode the semantic vectors of the sentences before and after the sentence and the semantic vector of the sentence by a long short-term memory network to obtain input semantics of the sentence;
[0037] a decoding module configured to decode the input semantics of the sentence by a long short-term memory network to obtain an updated sentence.
[0038] According to a third aspect of the embodiment of the present application, an electronic device for generating a text is provided, comprising:
[0039] one or more processors;
[0040] a storage device configured to store one or more programs,
[0041] When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.
[0042] According to a fourth aspect of the embodiment of the present application, a computer readable medium having a computer program stored thereon is provided, the program being executed by a processor to implement the method as described above.
[0043] An embodiment of the above application has the following advantages or beneficial effects: because the text is generated according to keywords, the text includes one or more sentences; according to the semantic vectors of the previous and next sentences of the sentence and the semantic vector of the sentence, the input semantics of the sentence is obtained by encoding using a long short-term memory network; the input semantics of the sentence is decoded by the long short-term memory network to obtain an updated sentence, and the updating of the sentence is completed. Updating the sentence with the previous and next sentences of the sentence can improve the logicality of the generated text, and further improve the efficiency of editing the text.
[0044] Further effects of the above non-conventional optional mode will be described below in conjunction with the specific embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0045] The accompanying drawings are used to better understand the present application and do not constitute an improper limitation on the present application. Among them:
[0046] Fig. 1 is a schematic diagram of the main process of the method for generating text according to an embodiment of the present application;
[0047] Fig. 2 is a schematic diagram of the method for generating text according to an embodiment of the present application;
[0048] Fig. 3 is a schematic diagram of the sentence encoding according to an embodiment of the present application;
[0049] Fig. 4 is a schematic diagram of another sentence encoding according to an embodiment of the present application;
[0050] Fig. 5 is a schematic diagram of the process of constructing a preset word library vector according to an embodiment of the present application;
[0051] Fig. 6 is a schematic diagram of the main structure of the device for generating text according to an embodiment of the present application
[0052] Fig. 7 is an exemplary system architecture diagram to which embodiments of the present application can be applied;
[0053] Fig. 8 is a structural schematic diagram of a computer system of a terminal device or a server suitable for implementing an embodiment of the present application. DETAILED DESCRIPTION
[0054] The exemplary embodiments of the present application are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present application to help understanding, and should be considered only as exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Also, for the sake of clarity and conciseness, the description below omits the description of well-known functions and structures.
[0055] Artificial intelligence technology represented by deep learning has made more and more breakthroughs, and can be applied to generate text. For example, the text generation process is regarded as a machine translation process. The previous sentence is regarded as a source sentence, the next sentence is regarded as a target sentence, the next sentence is generated according to a preset keyword, and the above process is repeated to generate text.
[0056] When generating text in the above manner, only the previous information is considered and the context is not considered, the context connection is loose, and the logic of the generated text is poor, which reduces the efficiency of editing the text.
[0057] In order to solve the technical problem that the efficiency of editing the text is low, the technical solutions in the embodiments of the present application can be used.
[0058] Referring to Fig. 1 , Fig. 1 is a schematic diagram of the main process of the method for generating text according to the embodiment of the present application, and the sentence is updated by the semantic vector of the previous and next sentences, and then the text is updated. As shown in Fig. 1 , the method comprises the following steps:
[0059] S101, generating text according to keywords, the text comprising one or more sentences.
[0060] In the embodiment of the present application, the keyword is the basis for generating the text. The keyword can be preset. As an example, one sentence can be generated according to one keyword, and the text is composed of one or more sentences.
[0061] A plurality of keywords are preset: K is a set of keywords, k i is the i-th keyword, and there are n keywords in total. The value of i is greater than or equal to 1 and less than n. Each keyword corresponds to a generated sentence. Referring to Table 1, Table 1 includes keywords, sentences, and the correspondence between keywords and sentences.
[0062] Table 1
[0063] Key words Sentence Moonlight Moonlight Farewell Farewell Heavy Heavy
[0064] Table 1 includes three keywords, each of which corresponds to a generated sentence. The keyword is moonlight, the corresponding sentence is moonlight; the keyword is sending, the corresponding sentence is sending; the keyword is heavy, the corresponding sentence is deep emotion.
[0065] In the embodiment of the present application, the Seq2Seq model can be used, and the generated sentence and the keyword of the next sentence are used as input, and the next sentence is used as target sentence output.
[0066] Specifically, the generated sentence and the keyword of the next sentence are first converted into vectors, and then encoded based on a Long Short-Term Memory (LSTM) to obtain the input semantics c of the next sentence t .
[0067] The decoding end also uses LSTM for decoding. In the decoding process, the hidden state s of the next sentence is obtained based on the input semantics c of the next sentence t and the output word w of the generated sentence decoding t-1 . t Specifically, as shown in formula (1).
[0068]
[0069] wherein c t is the input semantics learned through an attention mechanism, indicating that the decoder adopts different weights to represent the input vector when decoding the hidden state at the current time.
[0070] Based on the input semantics c of the next sentence t , combined with formula (1), the hidden state s of the next sentence is obtained t . Through the hidden state s of the next sentence t and the vector of the keyword of the next sentence, the next sentence is obtained by using LSTM for decoding.
[0071] Referring to Fig. 2 , Fig. 2 is a schematic diagram of generating text according to an embodiment of the present application. Wherein, Fig. 2 The left side of the input semantics c in the encoding process is the encoding process, and the right side of the input semantics c is the decoding process.
[0072] In the encoding process, the generated sentence and the keyword of the next sentence are taken as input. For example, the generated sentence includes: blowing in the wind, and the keyword: looking back. Then, the generated sentence is segmented, and the segmentation result is: blowing, in, and wind. Next, the words are vectorized, that is, the words are represented in the form of vectors. As an example, the words can be vectorized by using OneHot or Term Frequency-Inverse Document Frequency (TF-IDF). Each vectorized word is input into the LSTM, and after the input semantics c, the decoding process is entered.
[0073] In the decoding process, the first word of the next sentence is output by inputting the input semantics c into the LSTM, and then the first word is input into the LSTM as an input word after vectorization, and the second word of the next sentence is output: turn back. In the above manner, the third word: you are there, and the fourth word: there are obtained in turn. Thus, the next sentence: turn back you are there is output.
[0074] According to the example in Fig. 2 , each sentence in the text is generated in turn in combination with the keywords, and finally the text is constituted based on the generated sentences. The text is marked as , wherein each keyword corresponds to a sentence, and there are n sentences in total.
[0075] In S102, the input semantics of the sentence is obtained by encoding the semantics vectors of the previous and next sentences of the sentence and the semantics vector of the sentence by using the LSTM.
[0076] Fig. 2 In the example in , the next sentence is generated according to the previous sentence, only the previous information is considered, and the following information is not referred to, so it is difficult to better achieve the context connection.
[0077] In an embodiment of the present application, the input semantics of the sentence can be obtained by encoding the semantics vectors of the previous and next sentences of the sentence and the semantics vector of the sentence by using the LSTM.
[0078] The text includes one or more sentences, and the LSTM is used to encode the sentences in the text in turn according to the order of the sentences in the text. The sentences are selected according to the order of the sentences in the text.
[0079] In the encoding process, not only the previous m sentences l i-m:i-1 in the text are considered, but also the next m sentences l i+m:i+1 of the generated text are considered. i-m:i-1 , i is the i-th keyword, and each keyword corresponds to a sentence in an example; and m is a positive integer.
[0080] In an embodiment of the present application, in order to effectively use the context information, the previous m sentences and the next m sentences of the sentence in the text are encoded by using the bidirectional long short-term memory network (Bi-LSTM) to obtain bidirectional semantics information.
[0081]
[0082]
[0083] wherein e h is a sentence, Indicates a forward-hidden state. This represents the backward hidden state, which can be utilized. and Represents bidirectional semantic information:
[0084]
[0085] By utilizing a pre-defined attention model and combining bidirectional semantic information, semantic vectors for the preceding and following sentences of a statement are obtained. The attention model is a pre-configured LSTM model. When processing each word in the output sequence, the attention model focuses on words considered more important in the input sequence.
[0086] In the above embodiment, the semantic vectors of the preceding and following sentences of the text are obtained, which enables encoding by combining the preceding and following sentences of the sentence.
[0087] Statements are the foundation of encoding. Statements need to be encoded to obtain their semantic vectors.
[0088] In one embodiment of the present invention, statement l can be encoded first using Bi-LSTM, and then a preset attention model can be used to obtain the semantic vector of the statement.
[0089] See Fig. 3 , Fig. 3 This is a schematic diagram of statement encoding according to an embodiment of the present invention. Fig. 3 It mainly consists of two parts: the left part and the right part.
[0090] Fig. 3 The left part encodes the first m sentences and the last m sentences of the statement by combining them with a Bi-LSTM that includes multiple LSTMs, and then outputs the semantic vectors of the sentences before and after the statement through a pre-defined attention model.
[0091] Fig. 3 The right part of the algorithm takes the statement as input to multiple LSTMs and then outputs the semantic vector of the statement through a pre-defined attention model.
[0092] The input semantics are determined based on the semantic vectors of the preceding and following sentences and the semantic vector of the statement itself.
[0093] Specifically: That is, we get c in formula (1) t , due to s t-1 The parameter is known, e yt-1 Since the parameters are known, decoding can be achieved.
[0094] See Fig. 4 , Fig. 4is a schematic diagram of a semantic vector of another update statement according to an embodiment of the present application. Fig. 4 The embodiment in the middle differs from Fig. 3 The embodiment in the middle differs from
[0095] Specifically, Fig. 4 Mainly includes three parts, left part, middle part and right part.
[0096] Fig. 4 The left part of the embodiment, the first m sentences of the statement and the last m sentences of the statement are encoded by Bi-LSTM including multiple LSTMs, and then the semantic vector of the context of the statement is output by a preset attention model.
[0097] Fig. 4 The middle part of the embodiment, the statement is input into multiple LSTMs, and then the semantic vector of the statement is output by a preset attention model.
[0098] Fig. 4 The right part of the embodiment, k i and w i are input, k i is the ith keyword, w i is a word in the preset vocabulary, and the preset vocabulary w i and k i are encoded by a preset attention model to obtain a preset vocabulary vector i
[0099]
[0100] e w is an embedding vector representation corresponding to each word in the preset vocabulary, and a w is the attention weight corresponding to the word.
[0101] According to the semantic vector of the context of the statement, the semantic vector of the statement and the preset vocabulary vector of the statement, the input semantic is determined.
[0102] Specifically, That is, c t in formula (1) is obtained, since s t-1 is a known parameter, is a known parameter, and then decoding can be realized.
[0103] As can be seen, Fig. 4The embodiment in the application is based on the semantic vectors of the context of the sentence and the semantic vector of the sentence, and combines the preset vocabulary vector of the sentence to determine the input semantics of the sentence. The preset vocabulary involved in the preset vocabulary vector is preset based on the text generated according to the keyword. In this way, each sentence can be polished based on the preset vocabulary, thereby improving the rich words of each sentence.
[0104] Referring to Fig. 5 , Fig. 5 is a schematic diagram of a process of constituting a preset vocabulary vector according to an embodiment of the application, and specifically includes:
[0105] S501, according to the sentence and the keyword corresponding to the sentence, selecting a similar sentence of the sentence.
[0106] The preset text library includes a plurality of sentences, which can be selected from famous works. According to the sentence l and the keyword k corresponding to the sentence in S101, the preset text library is searched to select the first A related sentences. Exemplarily, A is equal to 20.
[0107] The Jaccard similarity of the sentence l and the related sentences is calculated respectively. Exemplarily, the most similar one of the related sentences with the above similarity between [0.3, 0.7] is selected as the similar sentence, and the similar sentence is denoted as r'. The Jaccard similarity is used to compare the similarity and difference between the limited sample sets. The larger the Jaccard value is, the higher the sample similarity is.
[0108] S502, selecting the words in the sentence, and constituting the first vocabulary of the sentence according to the word frequency inverse text frequency sorting, selecting the words in the similar sentence, and constituting the second vocabulary of the sentence according to the word frequency inverse text frequency sorting.
[0109] The words in l are selected, and the first vocabulary of l is constituted according to the TF-IDF sorting. The words in r' are selected, and the second vocabulary of l is constituted according to the TF-IDF sorting. It can be understood that the words in the first vocabulary are the words in l, and the words in the second vocabulary are the words in the similar sentence of l. Exemplarily, according to the TF-IDF from high to low sorting, the words with higher importance degree are arranged in the front in the first vocabulary or the second vocabulary.
[0110] In an embodiment of the application, considering the influence of the word class on the semantics, nouns, adjectives and verbs often have more rich semantic information. In the process of constituting the vocabulary, the word class in l is marked, the nouns, adjectives and verbs are selected, and the first vocabulary of l is constituted. Correspondingly, the word class in r' is marked, the nouns, adjectives and verbs are selected, and the second vocabulary of l is constituted.
[0111] S503, screening the words not in the first word library from the second word library in the order from high to low according to the TF-IDF, taking the first Y screened words as the polishing words of the sentence, Y being a preset value greater than or equal to 1.
[0112] There can be the same words in the first word library and the second word library. Then, in order to select the polishing words that can polish the sentence, it is necessary to screen the words not in the first word library from the second word library. Specifically, the words in the second word library have been sorted according to the TF-IDF, so the words not in the first word library can be screened from the second word library in the order from high to low according to the TF-IDF, and the first Y screened words are taken as the polishing words of the sentence. Wherein, Y is a preset value greater than or equal to 1. That is, the polishing words belong to the second word library and do not belong to the first word library.
[0113] The polishing words w i constitute a preset word library Wherein, N iw is a preset parameter, Y is equal to N iw .
[0114] S504, the polishing words and the keywords corresponding to the sentence are jointly coded to obtain a preset word library vector of the sentence.
[0115] w i and k i are jointly coded through a preset attention model to obtain a preset word library vector i
[0116] The text includes one or more sentences, and according to S501 to S504, the word library vector of each sentence in the text is obtained. Further, the preset word library vector is constituted by the word library vectors of all sentences in the text.
[0117] In the above embodiment, on the basis of the sentences in the text, the polishing words of each sentence are screened through similar sentences, and then the preset word library vector of the sentence is constructed. Thus, the polishing of the text can be realized.
[0118] S103, decoding the input semantics of the sentence through the long short-term memory network to obtain an updated sentence.
[0119] According to the input semantics of the sentence, the LSTM can be decoded to obtain an updated sentence.
[0120] In an embodiment of the present application, after obtaining the updated sentence, one or more sentences in the text can also be updated sentence by sentence to generate a text including all updated sentences.
[0121] The text generated in S101 includes one or more sentences, and according to S102 and S103, one or more sentences of the text are updated according to the order of the sentences in the text. Finally, the updated text is generated. The updated text can include all updated sentences.
[0122] In the above embodiment, the input semantics of the sentence is obtained by encoding the semantic vectors of the previous and next sentences of the sentence and the semantic vector of the sentence by using the LSTM; then, the updated sentence is obtained by decoding the input semantics of the sentence by using the LSTM. The sentence is updated according to the previous and next sentences, and the updated sentence not only considers the previous sentence but also considers the next sentence, so that the logicality of the text is enhanced, and the efficiency of editing the text is improved.
[0123] In addition, the sentence can also be polished by the preset word library. The richness of the words in the text and the coherence of the context are further improved.
[0124] Fig. 6 is a schematic diagram of the main structure of the text generation device according to an embodiment of the present application. The text generation device can implement the text generation method, as shown in Fig. 6 The text generation device specifically includes:
[0125] The generation module 601 is configured to generate a text according to a keyword, and the text includes one or more sentences.
[0126] The encoding module 602 is configured to encode the input semantics of the sentence by using the long short-term memory network according to the semantic vectors of the previous and next sentences of the sentence and the semantic vector of the sentence.
[0127] The decoding module 603 is configured to decode the input semantics of the sentence by using the long short-term memory network to obtain an updated sentence.
[0128] In an embodiment of the present application, the encoding module 603 is specifically configured to encode the input semantics of the sentence by using the long short-term memory network according to the semantic vectors of the previous and next sentences of the sentence, the semantic vector of the sentence and the preset word library vector of the sentence.
[0129] In an embodiment of the present application, the word library module 605 is further configured to select a similar sentence of the sentence according to the keyword corresponding to the sentence and the keyword corresponding to the similar sentence;
[0130] The words in the selected sentence are sorted according to the word frequency-inverse document frequency to form a first word library of the sentence, and the words in the similar sentence are sorted according to the word frequency-inverse document frequency to form a second word library of the sentence;
[0131] The words not in the first word library are filtered from the second word library according to the word frequency-inverse document frequency from high to low, and the first Y filtered words are selected as the polishing words of the sentence, and Y is a preset value greater than or equal to 1.
[0132] The polishing word and the keyword corresponding to the sentence are jointly coded to obtain a preset word library vector of the sentence.
[0133] In an embodiment of the present application, the word library module 605 is specifically configured to select nouns, adjectives and verbs in the sentence to form a first word library of the sentence.
[0134] The nouns, adjectives and verbs in the similar sentence are selected to form a second word library of the sentence.
[0135] In an embodiment of the present application, the word library module 605 is specifically configured to search for the first 20 related sentences in the preset text library according to the sentence and the keyword corresponding to the sentence.
[0136] The Jaccard similarity of the sentence and the related sentence is calculated, and the most similar related sentence with the Jaccard similarity between 0.3 and 0.7 is selected as the similar sentence.
[0137] In an embodiment of the present application, the generation module 601 is specifically configured to convert the keyword of the next sentence and the generated current sentence into vectors, and encode the input semantics of the next sentence based on a long short-term memory network.
[0138] According to the input semantics of the next sentence, the output word in the generated current sentence and the hidden state of the generated current sentence, the hidden state of the next sentence is determined.
[0139] The next sentence is decoded by the hidden state of the next sentence and the vector of the keyword of the next sentence.
[0140] The text is generated by the generated current sentence and the next sentence.
[0141] In an embodiment of the present application, it further includes an updating module 604 for updating one or more sentences in the text sentence by sentence, and generating a text including all updated sentences.
[0142] In an embodiment of the present application, the device further includes a sentence module 606 for encoding the sentence by a bidirectional long short-term memory network, and then obtaining a semantic vector of the sentence by using a preset attention model.
[0143] In an embodiment of the present application, the device further includes a previous and next sentence module 607 for encoding m sentences included in the previous context of the sentence in the text and m sentences included in the next context of the sentence in the text by a bidirectional long short-term memory network to obtain bidirectional semantic information, m being a positive integer.
[0144] The semantic vector of the previous and next sentence of the sentence is obtained by using a preset attention model in combination with the bidirectional semantic information.
[0145] Fig. 7 An exemplary system architecture 700 in which a method for generating text or a device for generating text according to embodiments of the present application can be applied is shown.
[0146] As shown in Fig. 7 , the system architecture 700 can include terminal devices 701, 702, 703, a network 704 and a server 705. The network 704 is a medium for providing a communication link between the terminal devices 701, 702, 703 and the server 705. The network 704 can include various connection types, such as wired, wireless communication links or fiber optic cables, etc.
[0147] A user can use the terminal devices 701, 702, 703 to interact with the server 705 through the network 704 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 701, 702, 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0148] The terminal devices 701, 702, 703 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers and desktop computers, etc.
[0149] The server 705 can be a server providing various services, such as a background management server providing support for a user browsing a shopping website using the terminal devices 701, 702, 703 (only as an example). The background management server can analyze and process received product information query requests and other data, and feed back the processing results (such as target push information, product information - only as examples) to the terminal devices.
[0150] It should be noted that the method for generating text provided by embodiments of the present application is generally executed by the server 705, and accordingly, the device for generating text is generally provided in the server 705.
[0151] It should be understood that Fig. 7 the number of terminal devices, networks and servers in
[0152] Reference is made to Fig. 8 , which shows a structural diagram of a computer system 800 of a terminal device suitable for implementing embodiments of the present application. Fig. 8 The terminal device shown is only an example and should not impose any limitation on the functions and use range of embodiments of the present application.
[0153] AsFig. 8 As shown, the computer system 800 includes a central processing unit (CPU) 801 which can perform various appropriate actions and processes in accordance with programs stored in a read only memory (ROM) 802 or loaded from a storage section 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0154] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a display such as a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as necessary. A removable recording medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is attached to the drive 810 as necessary, so that a computer program read therefrom is installed into the storage section 808 as necessary.
[0155] In particular, the processes described above with reference to the flowcharts can be implemented as a computer software program in accordance with the embodiments disclosed herein. For example, the embodiments disclosed herein include a computer program product comprising a computer program carried on a computer readable medium, the computer program comprising program code for performing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication section 809 and / or installed from the removable recording medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-described functions defined in the system of the present application are performed.
[0156] It should be noted that the computer-readable medium shown in the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or component. In the present application, the computer-readable signal medium can include a data signal carried in a baseband or as a part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to an electromagnetic signal, an optical signal or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate or transmit a program for use by or in conjunction with an instruction execution system, device or component. The program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0157] The flowcharts and block diagrams in the drawings illustrate the possible implementation architectures, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a program segment or a part of code containing one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different order than that shown in the drawings. For example, two blocks that are shown in succession can actually be executed substantially in parallel, and sometimes in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams or flowcharts, and the combination of blocks in the block diagrams or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0158] The modules described in the embodiments of the present application can be implemented in the form of software or in the form of hardware. The described modules can also be arranged in a processor, for example, a processor can be described as including a sending unit, an obtaining unit, a determining unit and a first processing unit. In some cases, the names of these units do not constitute a limitation on the units themselves, for example, the sending unit can also be described as "a unit for sending a picture obtaining request to a connected server".
[0159] As another aspect, the present application also provides a computer readable medium, which can be included in the device described in the above embodiments, or can exist independently without being assembled into the device. The computer readable medium carries one or more programs, which, when executed by the device, cause the device to include:
[0160] Generating a text according to the keyword, the text including one or more sentences;
[0161] According to the semantic vector of the context sentence and the semantic vector of the sentence, the input semantic of the sentence is obtained by encoding using a long short-term memory network;
[0162] The input semantic of the sentence is decoded by the long short-term memory network to obtain an updated sentence.
[0163] According to the technical scheme of the embodiments of the present application, because the text is generated according to the keyword, the text including one or more sentences; according to the semantic vector of the context sentence and the semantic vector of the sentence, the input semantic of the sentence is obtained by encoding using a long short-term memory network; the input semantic of the sentence is decoded by the long short-term memory network to obtain an updated sentence, and the updating of the sentence is completed. Updating the sentence according to the context sentence can improve the logicality of the generated text, and further improve the efficiency of editing the text.
[0164] The above specific embodiments do not constitute a limitation on the protection scope of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made depending on design requirements and other factors. Any modification, equivalent replacement and improvement made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A method of generating text, characterized by, The method comprises the following steps: Converting the keywords of the next sentence and the generated current sentence into vectors, and encoding the input semantics of the next sentence based on a long short-term memory network; Determining the hidden state of the next sentence according to the input semantics of the next sentence, the output words in the generated current sentence, and the hidden state of the generated current sentence; Decoding the hidden state of the next sentence and the vector of the keywords of the next sentence to obtain the next sentence; and generating the text from the generated current sentence and the next sentence, wherein the text comprises a plurality of sentences; Encoding the input semantics of the sentence by using a long short-term memory network according to the semantic vectors of the previous and next sentences of the sentence, the semantic vector of the sentence, and the preset vocabulary vector of the sentence; Decoding the input semantics of the sentence by using a long short-term memory network to obtain an updated sentence; Before the step of encoding the input semantics of the sentence by using a long short-term memory network according to the semantic vectors of the previous and next sentences of the sentence, the semantic vector of the sentence, and the preset vocabulary vector of the sentence, the method further comprises the following steps: Selecting similar sentences of the sentence according to the sentence and the keywords corresponding to the sentence; Selecting words in the sentence to form a first vocabulary of the sentence in the order of term frequency-inverse document frequency, and selecting words in the similar sentences to form a second vocabulary of the sentence in the order of term frequency-inverse document frequency; Filtering words in the second vocabulary that are not in the first vocabulary in the order from high to low of term frequency-inverse document frequency, and selecting the first Y filtered words as polishing words of the sentence, wherein Y is a preset value greater than or equal to 1; Encoding the polishing words of the sentence and the keywords corresponding to the sentence to obtain a preset vocabulary vector of the sentence.
2. The method of claim 1, wherein, The step of selecting words in the sentence to form a first vocabulary of the sentence and selecting words in the similar sentences to form a second vocabulary of the sentence comprises the following steps: Selecting nouns, adjectives, and verbs in the sentence to form the first vocabulary of the sentence; Selecting nouns, adjectives, and verbs in the similar sentences to form the second vocabulary of the sentence.
3. The method of claim 1, wherein, The step of selecting similar sentences of the sentence according to the sentence and the keywords corresponding to the sentence comprises the following steps: Retrieving the first 20 related sentences in a preset text library according to the sentence and the keywords corresponding to the sentence; Calculating the Jaccard similarity between the sentence and the related sentences, and selecting the related sentence with the Jaccard similarity between 0.3 and 0.7 as the most similar similar sentence.
4. The method of claim 1, wherein, After the step of decoding the input semantics of the sentence by using a long short-term memory network to obtain an updated sentence, the method further comprises the following steps: Updating one or more sentences in the text sentence by sentence to generate a text comprising all updated sentences.
5. The method of claim 1, wherein, The method further comprises the following steps: Encoding the sentence by using a bidirectional long short-term memory network, and then obtaining a semantic vector of the sentence by using a preset attention model.
6. The method of claim 1, wherein, The method further comprises the following steps: The m sentences included in the context of the sentence and the m sentences included in the context of the sentence are encoded by a bidirectional long short-term memory network to obtain bidirectional semantic information, m being a positive integer; A preset attention model is used to obtain semantic vectors of the context and the sentence of the sentence based on the bidirectional semantic information.
7. An apparatus for generating text, characterized by The method comprises: A generation module is configured to convert keywords of a next sentence and a generated current sentence into vectors, and encode the next sentence based on a long short-term memory network to obtain input semantics of the next sentence; A hidden state of the next sentence is determined based on the input semantics of the next sentence, output words in the generated current sentence, and a hidden state of the generated current sentence; The next sentence is decoded based on the hidden state of the next sentence and the vector of the keywords of the next sentence; and the text is generated based on the generated current sentence and the next sentence, the text comprising a plurality of sentences; An encoding module is configured to encode input semantics of the sentence based on semantic vectors of the context and the sentence of the sentence, semantic vectors of the sentence, and a preset vocabulary vector of the sentence by using a long short-term memory network; A decoding module is configured to decode the input semantics of the sentence by using a long short-term memory network to obtain an updated sentence; A vocabulary module is configured to select similar sentences of a sentence based on the sentence and keywords corresponding to the sentence; Words in the selected sentences are sorted according to a word frequency-inverse document frequency to form a first vocabulary of the sentence, and words in the similar sentences are sorted according to a word frequency-inverse document frequency to form a second vocabulary of the sentence; Words not in the first vocabulary are filtered from the second vocabulary according to a word frequency-inverse document frequency from high to low, and the first Y filtered words are selected as polishing words of the sentence, Y being a preset value greater than or equal to 1; The polishing words and the keywords corresponding to the sentence are jointly encoded to obtain the preset vocabulary vector of the sentence.
8. An electronic device that generates text, the electronic device comprising: The method comprises: One or more processors; A storage device configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method of any one of claims 1-6.
9. A computer readable medium having stored thereon a computer program, characterized in that The program is executed by the processor to implement the method of any one of claims 1-6.
Citation Information
Patent Citations
Text generation method and device and storage medium
CN109635150A