Title generation method, device, electronic device and storage medium
By preprocessing and delimiter identification of the original corpus, using the title generation model for vector encoding and decoding, and combining the user style, the problem of unsmooth and unpersonalized title generation in the existing technology is solved, and the generation is consistent with semantics and User-style title.
Patent Information
- Application Number
- CN202011385255.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-01
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-12-01
AI Technical Summary
Existing title generation methods cannot generate titles that are smooth and semantic, and cannot effectively combine user styles to meet users' personalized needs.
By obtaining the original corpus for preprocessing and delimiter identification, the pre-built title generation model is used to perform vector encoding, semantic encoding and title sequence decoding, and the loss value is calculated to adjust the model parameters until the loss value is less than the threshold to generate titles that conform to the user's style. .
It realizes the generation of fluent and semantic titles, meets the personalized needs of users, and improves the semantic fluency and user satisfaction of title generation.
Smart Images

Figure CN112446207B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent decision making, and in particular to a title generation method, device, electronic device and computer-readable storage medium. Background Art
[0002] Title generation is to automatically generate corresponding titles from the original content. In financial public opinion events, title generation can be used as a means of information extraction to help dig out hot events in public opinion events. Similarly, in media websites such as financial news, eye-catching titles are automatically generated based on news, making users more inclined to click and read news, thereby increasing the exposure and clicks of the overall news.
[0003] At present, there are two problems with the title generation method: First, it is mainly based on the extraction method, that is, extracting important words from the article as the theme of the article, and then forming these words into titles according to certain grammatical rules, which cannot generate smooth and semantically consistent titles; second, the generated titles cannot be well combined with the user's style to generate titles that meet the user's personalized needs. Summary of the invention
[0004] The present invention provides a title generation method, device, electronic device and computer-readable storage medium, the main purpose of which is to generate a title that is smooth, semantically consistent and meets the user's style.
[0005] To achieve the above object, the present invention provides a method for generating a title, comprising:
[0006] Obtaining an original corpus, and performing a preprocessing operation on the original corpus to obtain a standard corpus;
[0007] Marking the standard corpus with separators to generate a target corpus;
[0008] Performing vector encoding on the target corpus using a pre-built title generation model to obtain a corpus vector set, and performing semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set;
[0009] Using the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculating a loss value between the decoded title and a label corresponding to the original corpus, and adjusting the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model;
[0010] Based on the title style input by the user, the trained title generation model is used to perform title generation on the corpus for which the title is to be generated, to obtain a generation result.
[0011] Optionally, the obtaining the original corpus includes:
[0012] Crawl the uniform resource locator address of the original corpus to be obtained, and character-identify the original corpus to be obtained, load the system interface corresponding to the original corpus to be obtained according to the uniform resource locator address, and obtain the corresponding original corpus from the system interface according to the character identification.
[0013] Optionally, the preprocessing operation on the original corpus to obtain a standard corpus includes:
[0014] Performing data cleaning on the original corpus to obtain an initial corpus;
[0015] Performing title sentence recognition and character calculation on the original titles in the initial corpus to obtain title categories;
[0016] Performing keyword extraction on the initial corpus to obtain a corpus keyword set, and screening out keywords that overlap with the original titles in the initial corpus from the corpus keyword set to obtain target keywords;
[0017] The initial corpus, title categories and target keywords are combined to obtain a standard corpus.
[0018] Optionally, the marking of separators on the standard corpus includes:
[0019] The standard corpus is marked with separators using the following method:
[0020] inputk=[CLS]content[SEP]kw[SEP]js[SEP]jc[SEP]title[EOS]
[0021] Among them, inputk represents the target corpus, [CLS] represents the sentence start tag, [SEP] represents the separator tag, [EOS] represents the sentence end tag, content represents the text content in the standard corpus, kw represents the target keyword in the standard corpus, js represents the sentence pattern of the original title category in the standard corpus, jc represents the sentence length of the original title category in the standard corpus, and title represents the original title content in the standard corpus.
[0022] Optionally, the using a pre-built title generation model to perform vector encoding on the target corpus to obtain a corpus vector set includes:
[0023] Performing character encoding on the target corpus using the character encoding algorithm in the title generation model;
[0024] Performing position encoding on the character-encoded target corpus using a position encoding algorithm in the title generation model;
[0025] The target corpus after position encoding is paragraph-encoded using the paragraph encoding algorithm in the title generation model to obtain a corpus vector set.
[0026] Optionally, the step of using a decoder in the title generation model to decode the semantic vector set into a title sequence comprises:
[0027] The title sequence is decoded for the semantic vector set using the following method:
[0028]
[0029] Among them, f t Indicates the decoded header, represents the bias of the cell in the decoder, w f represents the activation factor of the legacy decoder, The peak value of the semantic vector of the semantic vector set at the decoder time t-1, x t represents the semantic vector of the semantic vector set input at time t, b f Represents the weights of the cells in the decoder.
[0030] Optionally, calculating the loss value of the decoded title and the label corresponding to the original corpus includes:
[0031] The loss value of the decoded title and the label corresponding to the original corpus is calculated using the following method:
[0032]
[0033] Among them, loss represents the loss value, y i Indicates the i-th character of the decoded title, represents the i-th character of the original title of the original corpus, n represents the number of characters in the original title of the original corpus, and h L Represents the Lth semantic vector in the semantic vector set.
[0034] In order to solve the above problem, the present invention further provides a title generating device, the device comprising:
[0035] A preprocessing module is used to obtain an original corpus, perform preprocessing operations on the original corpus, and obtain a standard corpus;
[0036] An identification module, used for marking the separators of the standard corpus to generate a target corpus;
[0037] A model training module, used to perform vector encoding on the target corpus using a pre-built title generation model to obtain a corpus vector set, and perform semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set;
[0038] The model training module is further used to use the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculate the loss value between the decoded title and the label corresponding to the original corpus, and adjust the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model;
[0039] The generation module is used to generate titles for the corpus to be generated titles based on the title style input by the user and using the trained title generation model to obtain a generation result.
[0040] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0041] at least one processor; and,
[0042] a memory communicatively connected to the at least one processor; wherein,
[0043] 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 to implement the above-mentioned title generation method.
[0044] In order to solve the above problem, the present invention further provides a computer-readable storage medium, wherein at least one computer program is stored in the computer-readable storage medium, and the at least one computer program is executed by a processor in an electronic device to implement the above-mentioned title generation method.
[0045] The embodiment of the present invention first performs preprocessing operations and separator identification on the original corpus to generate a target corpus. The titles, keyword information and text content of different sentence patterns and sentence lengths in the original corpus can be jointly trained for model training to ensure that users can generate different styles of titles they want based on different forms of control information; secondly, the embodiment of the present invention uses a pre-built title generation model to vector encode, semantic encode and title sequence decode the target corpus to obtain a decoded title, calculate the loss value of the decoded title and the corresponding label of the original corpus, and adjust the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold. The trained title generation model can well learn the contextual semantic information between the text content in the target corpus and improve the semantic fluency of subsequent title generation; further, the embodiment of the present invention uses the trained title generation model to generate titles for the corpus to be generated based on the title style input by the user to obtain a generation result. Therefore, a title generation method, device, electronic device and storage medium proposed by the present invention can generate titles that are fluent, semantically consistent and satisfy the user's style. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 A flowchart of a method for generating a title according to an embodiment of the present invention;
[0047] Figure 2 In the first embodiment of the present invention Figure 1 A detailed flowchart of one of the steps in the title generation method provided;
[0048] Figure 3 A schematic diagram of a module of a title generating device provided by an embodiment of the present invention;
[0049] Figure 4 A schematic diagram of the internal structure of an electronic device for implementing a title 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 title. The execution subject of the method for generating a title includes but is not limited to at least one of the electronic devices such as a server and a terminal that can be configured to execute the method provided by the embodiment of the present application. In other words, the method for generating a title 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.
[0053] Reference Figure 1 FIG. 1 is a flow chart of a method for generating a title according to an embodiment of the present invention. In the embodiment of the present invention, the method for generating a title includes:
[0054] S1. Obtain an original corpus, and perform a preprocessing operation on the original corpus to obtain a standard corpus.
[0055] In the embodiment of the present invention, the original corpus refers to news data, including original news content and original news headlines. Further, the embodiment of the present invention crawls the original corpus from the web page through a crawler tool, and optionally, the crawler tool is built based on node.js technology.
[0056] In detail, the obtaining of the original corpus through the crawler tool includes: using node.js to crawl the Uniform Resource Locator (URL) address of the original corpus to be obtained, and character-marking the original corpus to be obtained, and according to the URL address, loading the system interface corresponding to the original corpus to be obtained, and according to the character mark, obtaining the corresponding original corpus from the system interface.
[0057] It should be understood that the crawled original corpus contains a large amount of useless data. Therefore, the embodiment of the present invention performs a preprocessing operation on the original corpus to improve the processing efficiency of subsequent data.
[0058] Specifically, the preprocessing operation on the original corpus to obtain the standard corpus includes: performing data cleaning on the original corpus to obtain an initial corpus, performing title sentence recognition and character calculation on the original titles in the initial corpus to obtain title categories, performing keyword extraction on the initial corpus to obtain a corpus keyword set, and screening out keywords that overlap with the original titles in the initial corpus from the corpus keyword set to obtain target keywords, and combining the initial corpus, title categories and target keywords to obtain a standard corpus.
[0059] Wherein, the data cleaning of the original corpus includes: filtering out garbled symbols and special symbols of web pages in the original corpus, and performing sentence processing on the filtered original corpus according to punctuation marks (.?!;;!?), obtaining a sentence corpus, and removing single sentences with more than a first preset number of characters and original titles with less than a second preset number of characters and more than a third preset number of characters from the sentence corpus to obtain a standard corpus. Optionally, the first preset number of data is 500, the second preset number is 4, and the third preset number is 60.
[0060] Furthermore, the title sentence pattern recognition and character calculation of the original titles in the initial corpus to obtain the title category includes: using the sentence pattern to recognize the title sentence pattern of the original title (such as a declarative sentence, a judgment sentence, and a question sentence), identifying the title length of the original title (short title, medium title, and long title) by the number of characters, and summarizing the title sentence pattern and title length to obtain the title category of the original title. Among them, the embodiment of the present invention marks the original title with a title length of less than 12 characters as a short title, the original title with a title length between 12 and 26 characters as a medium title, and the original title with a title length of more than 26 characters as a long title.
[0061] Furthermore, in an embodiment of the present invention, keyword extraction of the initial corpus is implemented by a keyword extraction algorithm, and the keyword extraction algorithm may be a TF-IDF algorithm or a TextRank algorithm.
[0062] Based on the above-mentioned implementation means, the present invention can identify the text content, keywords, original title content and original title category of the original corpus in the corpus by preprocessing the original corpus, so as to better train the subsequent title generation model and improve the robustness of the subsequent model training, thereby improving the semantic fluency of the title generation and the title style that meets user needs.
[0063] S2. Mark the standard corpus with separators to generate a target corpus.
[0064] In the embodiment of the present invention, the standard corpus is marked with corpus separators to determine the position information of the standard corpus in the standard corpus, so as to better perform model training.
[0065] In detail, the method of marking the standard corpus with separators to generate a target corpus includes: obtaining the beginning of a sentence, the end of a sentence, the text content, the target keyword, the original title category and the original title content of the standard corpus in the standard corpus, adding a beginning of a sentence mark before the beginning of the sentence, adding an end of a sentence mark after the end of the sentence, adding a separator mark between the text content, the target keyword, the original title category and the original title content, splicing the beginning of a sentence, the end of a sentence, the text content, the target keyword, the original title category and the original title content after the marking to obtain the target corpus, and generating the target corpus according to the target corpus.
[0066] In an optional embodiment, the standard corpus is marked with separators using the following method:
[0067] inputk=[CLS]content[SEP]kw[SEP]js[SEP]jc[SEP]title[EOS]
[0068] Among them, inputk represents the target corpus, [CLS] represents the sentence start tag, [SEP] represents the separator tag, [EOS] represents the sentence end tag, content represents the text content, kw represents the target keyword, js represents the sentence pattern in the original title category, jc represents the sentence length in the original title category, and title represents the original title content.
[0069] Furthermore, in order to ensure the reusability of the target corpus, the target corpus can also be stored in a blockchain node.
[0070] S3. Use a pre-built title generation model to perform vector encoding on the target corpus to obtain a corpus vector set, and use an encoder in the title generation model to perform semantic encoding on the corpus vector set to obtain a semantic vector set, and aggregate all semantic vectors in the semantic vector set to obtain an aggregated semantic vector.
[0071] In an embodiment of the present invention, the pre-built title generation model includes: a UniLM model, which is used to generate a semantic text title with high fluency based on the title styles input by different users. Furthermore, in an embodiment of the present invention, vector encoding is performed on the target corpus to identify the text position information of the target corpus in the target corpus and to distinguish the segmentation information between the texts, which is used for encoder recognition of the subsequent title generation model.
[0072] For details, see Figure 2 As shown: the target corpus is vector-encoded using the pre-built title generation model to obtain a corpus vector set, including:
[0073] S20, performing character encoding on the target corpus using the character encoding algorithm in the title generation model;
[0074] S21, performing position encoding on the character-encoded target corpus using the position encoding algorithm in the title generation model;
[0075] S22. Perform paragraph encoding on the target corpus after position encoding using the paragraph encoding algorithm in the title generation model to obtain a corpus vector set.
[0076] In one of the optional embodiments of the present invention, the character encoding algorithm may be a Token Embedding algorithm, the position encoding algorithm may be a Position Embedding algorithm, and the paragraph encoding algorithm may be a TokenEmbedding algorithm.
[0077] Furthermore, the embodiment of the present invention utilizes the encoder in the title generation model to perform semantic encoding on the corpus vector set, so as to better learn the contextual semantic information between the text contents in the target corpus.
[0078] In detail, the method of using the encoder in the title generation model to semantically encode the corpus vector set to obtain the semantic vector set includes:
[0079] The forward encoder bi-LSTM of the encoder is used to perform forward semantic encoding on each corpus vector in the corpus vector set to obtain a forward semantic vector, the backward encoder bi-LSTM of the encoder is used to perform backward semantic encoding on each corpus vector in the corpus vector set to obtain a backward semantic vector, the forward semantic vector and the backward semantic vector are concatenated to obtain a semantic vector, and the semantic vector set is generated according to the semantic vector.
[0080] The forward semantic coding is to forward encode the corpus vector in a sequence from front to back, and the backward semantic coding is to backward encode the corpus vector in a sequence from back to front.
[0081] Based on the above implementation scheme, the generated semantic vector set can represent the correlation between different corpus vectors, thereby improving the accuracy of subsequent title generation.
[0082] S4. Use the decoder in the title generation model to decode the semantic vector set to obtain a decoded title, calculate the loss value between the decoded title and the label corresponding to the original corpus, and adjust the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model.
[0083] In the embodiment of the present invention, the decoder in the title generation model is used to decode the semantic vector set into a title sequence to obtain a decoded sequence title.
[0084] In one of the optional embodiments of the present invention, the title sequence is decoded for the semantic vector set using the following method:
[0085]
[0086] Among them, f t Indicates the decoded header, represents the bias of the cell in the decoder, w f represents the activation factor of the legacy decoder, The peak value of the semantic vector of the semantic vector set at the decoder time t-1, x t represents the semantic vector of the semantic vector set input at time t, b f Represents the weights of the cells in the decoder.
[0087] Furthermore, the embodiment of the present invention uses the loss function of the title generation model to calculate the loss value of the decoded title and the label corresponding to the original corpus, and adjusts the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model. The label refers to the original title of the original corpus, and the preset threshold is 0.1.
[0088] In an optional embodiment, the loss function includes:
[0089]
[0090] Among them, loss represents the loss value, y i Indicates the i-th character of the decoded title, represents the i-th character of the original title of the original corpus, n represents the number of characters in the original title of the original corpus, and h L Represents the Lth semantic vector in the semantic vector set.
[0091] S5. Based on the title style input by the user, the trained title generation model is used to generate titles for the corpus to be generated titles, and a generation result is obtained.
[0092] In the embodiment of the present invention, according to the title style input by the user, the trained title generation model is used to generate titles for the corpus to be generated, and a generation result is obtained. The title style refers to the sentence pattern and sentence length of the title that the user needs to generate.
[0093] The embodiment of the present invention first performs preprocessing operations and separator identification on the original corpus to generate a target corpus. The titles, keyword information and text content of different sentence patterns and lengths in the original corpus can be jointly trained with a model to ensure that users can generate titles of different styles based on different forms of control information; secondly, the embodiment of the present invention uses a pre-built title generation model to vector encode, semantic encode and title sequence decode the target corpus to obtain a decoded title, calculate the loss value of the decoded title and the label corresponding to the original corpus, and adjust the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold. The trained title generation model can be obtained, which can well learn the contextual semantic information between the text content in the target corpus and improve the semantic fluency of subsequent title generation; further, the embodiment of the present invention uses the title generation model to generate titles for the corpus to be generated based on the title style input by the user to obtain a generated result. Therefore, the present invention can generate titles that are fluent, semantically consistent and satisfy the user's style.
[0094] like Figure 3 The figure shows a functional module diagram of the title generating device of the present invention.
[0095] The title generation device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the title generation device can include a preprocessing module 101, an identification module 102, a model training module 103 and a generation module 104. The module described in 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.
[0096] In this embodiment, the functions of each module / unit are as follows:
[0097] The preprocessing module 101 is used to obtain an original corpus, and perform a preprocessing operation on the original corpus to obtain a standard corpus;
[0098] The identification module 102 is used to identify the separators of the standard corpus to generate a target corpus;
[0099] The model training module 103 is used to perform vector encoding on the target corpus set using a pre-built title generation model to obtain a corpus vector set, and perform semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set;
[0100] The model training module 103 is further used to use the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculate the loss value between the decoded title and the label corresponding to the original corpus, and adjust the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model;
[0101] The generating module 104 is used to generate titles for the corpus to be generated titles based on the title style input by the user and using the trained title generating model to obtain a generating result.
[0102] In detail, each module in the title generation device 100 in the embodiment of the present invention adopts the same method as above when used. Figure 1 and Figure 2 The title generation method described in the above is a technical method that can produce the same technical effect and will not be repeated here.
[0103] like Figure 4 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing the title generation method of the present invention.
[0104] The electronic device 1 may include a processor 10 , a memory 11 , and a bus, and may also include a computer program stored in the memory 11 and executable on the processor 10 , such as a title generation program 12 .
[0105] 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 (e.g., 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 the electronic device 1, such as a mobile hard disk of the electronic device 1. In other embodiments, the memory 11 may also be an external storage device of the electronic device 1, 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 1. Further, the memory 11 may also include both an internal storage unit of the electronic device 1 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 1, such as the code of the title generation program, etc., but also be used to temporarily store data that has been output or is to be output.
[0106] The processor 10 may be composed of an integrated circuit in some embodiments, 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, etc. The processor 10 is the control core (Control Unit) 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 title generation program, etc.), and calls data stored in the memory 11, so as to execute various functions of the electronic device 1 and process data.
[0107] The bus 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.
[0108] Figure 4 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 4 The 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.
[0109] For example, although not shown, the electronic device 1 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 any components such as one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device 1 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0110] Furthermore, the electronic device 1 may also include a network 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 1 and other electronic devices.
[0111] Optionally, the electronic device 1 may further include a user interface, which may be a display, an input unit (such as a keyboard), or a standard wired interface or 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) touch device. 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 1 and to display a visual user interface.
[0112] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0113] The title generation program 12 stored in the memory 11 in the electronic device 1 is a combination of multiple programs. When running in the processor 10, it can achieve:
[0114] Obtaining an original corpus, and performing a preprocessing operation on the original corpus to obtain a standard corpus;
[0115] Marking the standard corpus with separators to generate a target corpus;
[0116] Performing vector encoding on the target corpus using a pre-built title generation model to obtain a corpus vector set, and performing semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set;
[0117] Using the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculating a loss value between the decoded title and a label corresponding to the original corpus, and adjusting the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model;
[0118] Based on the title style input by the user, the trained title generation model is used to perform title generation on the corpus for which the title is to be generated, to obtain a generation result.
[0119] Specifically, the specific implementation method of the processor 10 for the above program can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0120] 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 non-volatile 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).
[0121] 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:
[0122] Obtaining an original corpus, and performing a preprocessing operation on the original corpus to obtain a standard corpus;
[0123] Marking the standard corpus with separators to generate a target corpus;
[0124] Performing vector encoding on the target corpus using a pre-built title generation model to obtain a corpus vector set, and performing semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set;
[0125] Using the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculating a loss value between the decoded title and a label corresponding to the original corpus, and adjusting the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model;
[0126] Based on the title style input by the user, the trained title generation model is used to perform title generation on the corpus for which the title is to be generated, to obtain a generation result.
[0127] 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.
[0128] 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.
[0129] 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.
[0130] 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.
[0131] 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.
[0132] 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.
[0133] 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 second and other words are used to indicate names, but not to indicate any particular order.
[0134] 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 method for generating a title, characterized in that: The method comprises: Obtaining an original corpus, and performing a preprocessing operation on the original corpus to obtain a standard corpus; Marking the standard corpus with separators to generate a target corpus; Performing vector encoding on the target corpus using a pre-built title generation model to obtain a corpus vector set, and performing semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set; Using the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculating a loss value between the decoded title and a label corresponding to the original corpus, and adjusting the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model; Based on the title style input by the user, the trained title generation model is used to generate titles for the corpus to be generated titles, and a generation result is obtained; The step of marking the separator of the standard corpus comprises: marking the separator of the standard corpus by using the following method: inputk=[CLS]content[SEP]kw[SEP]js[SEP]jc[SEP]title[EOS] Among them, inputk represents the target corpus, [CLS] represents the sentence start tag, [SEP] represents the separator tag, [EOS] represents the sentence end tag, content represents the text content in the standard corpus, kw represents the target keyword in the standard corpus, js represents the sentence pattern of the original title category in the standard corpus, jc represents the sentence length of the original title category in the standard corpus, and title represents the original title content in the standard corpus.
2. The title generation method according to claim 1, characterized in that: The obtaining of the original corpus comprises: Crawl the uniform resource locator address of the original corpus to be obtained, and character-identify the original corpus to be obtained, load the system interface corresponding to the original corpus to be obtained according to the uniform resource locator address, and obtain the corresponding original corpus from the system interface according to the character identification.
3. The title generation method according to claim 1, characterized in that: The preprocessing operation is performed on the original corpus to obtain a standard corpus, including: Performing data cleaning on the original corpus to obtain an initial corpus; Performing title sentence recognition and character calculation on the original titles in the initial corpus to obtain title categories; Performing keyword extraction on the initial corpus to obtain a corpus keyword set, and screening out keywords that overlap with the original titles in the initial corpus from the corpus keyword set to obtain target keywords; The initial corpus, title categories and target keywords are combined to obtain a standard corpus.
4. The title generation method according to claim 1, characterized in that: The method of using the pre-built title generation model to vector encode the target corpus to obtain a corpus vector set includes: Performing character encoding on the target corpus using the character encoding algorithm in the title generation model; Performing position encoding on the character-encoded target corpus using a position encoding algorithm in the title generation model; The target corpus after position encoding is paragraph-encoded using the paragraph encoding algorithm in the title generation model to obtain a corpus vector set.
5. The title generation method according to claim 1, characterized in that: The step of using the decoder in the title generation model to decode the semantic vector set into a title sequence comprises: The title sequence is decoded for the semantic vector set using the following method: Among them, f t Indicates the decoded header, represents the bias of the cell in the decoder, w f represents the activation factor of the decoder, The peak value of the semantic vector of the semantic vector set at the decoder time t-1, x t represents the semantic vector of the semantic vector set input at time t, b f Represents the weights of the cells in the decoder.
6. The title generation method according to any one of claims 1 to 5, characterized in that: The calculating the loss value of the decoded title and the label corresponding to the original corpus includes: The loss value of the decoded title and the label corresponding to the original corpus is calculated using the following method: Among them, loss represents the loss value, y i Indicates the i-th character of the decoded title, represents the i-th character of the original title of the original corpus, n represents the number of characters in the original title of the original corpus, and h L Represents the Lth semantic vector in the semantic vector set.
7. A title generation device, used to implement the title generation method according to any one of claims 1 to 6, characterized in that: The device comprises: A preprocessing module is used to obtain an original corpus, perform preprocessing operations on the original corpus, and obtain a standard corpus; An identification module, used for marking the separators of the standard corpus to generate a target corpus; A model training module, used to perform vector encoding on the target corpus using a pre-built title generation model to obtain a corpus vector set, and perform semantic encoding on the corpus vector set using an encoder in the title generation model to obtain a semantic vector set; The model training module is further used to use the decoder in the title generation model to decode the semantic vector set into a title sequence to obtain a decoded title, calculate the loss value between the decoded title and the label corresponding to the original corpus, and adjust the parameters of the title generation model according to the loss value until the loss value is less than a preset threshold, thereby obtaining a trained title generation model; The generation module is used to generate titles for the corpus to be generated titles based on the title style input by the user and using the trained title generation model to obtain a generation result.
8. 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 title generating method according to any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the title generating method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Title generation method and device, electronic device and storage medium
CN110717327A
Automatic news title generation method
CN111241816A
