Text generation method and device, electronic equipment and storage medium
By introducing knowledge graph and text generation models in RAG technology, we can determine the key entities and relationships of the target text content, and solve the problem of insufficient accuracy and deep semantic understanding of the existing technology in the handling of complex problems, achieving efficient and accurate text Content generation.
Patent Information
- Application Number
- CN202411092816.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-11-15
AI Technical Summary
The existing search-enhanced generation (RAG) technology is difficult to generate accurate and comprehensive text content when dealing with complex problems due to the limited scale of the knowledge base and insufficient semantic understanding ability, and can only stay in the surface-level semantic understanding, lacking deep semantics. Analytical and reasoning skills of relationships.
By determining the key entities and key entities relationships of the target text content based on the knowledge graph and text generation model, we can achieve efficient and accurate text content generation. The specific steps include: parsing the query request to determine keywords, building a target knowledge graph, using the text generation model for searching and analysis, and finally generating the target text content.
It improves the accuracy and richness of text content generation, can understand and analyze semantic relationships more deeply, enhances retrieval capabilities, and the generated text content is more accurate and comprehensive.
Smart Images

Figure CN118966165A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of artificial intelligence and natural language processing, and in particular to a text generation method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of information technology, especially the continuous breakthroughs in the field of artificial intelligence, deep learning technology has penetrated into every corner of society. Among them, Large Language Model (LLM), as an important branch of Natural Language Processing (NLP), has attracted widespread attention in the industry with its powerful text generation, understanding and reasoning capabilities.
[0003] At present, the retrieval-augmented generation (RAG) technology is usually used to retrieve and generate text content. However, the current RAG technology often relies on the similarity comparison mechanism of the embedded vector to retrieve relevant information in the knowledge base. This method may be effective enough when dealing with simple problems, but when facing complex problems, due to the limitation of the knowledge base scale and the lack of semantic understanding ability, the current RAG technology has great limitations in association analysis, making the retrieval ability particularly limited and difficult to generate accurate and comprehensive answers. In addition, when processing natural language, the current RAG technology can only stay at the surface level of semantic understanding and lacks the ability to analyze and reason about deep semantic relationships. Summary of the invention
[0004] The present invention provides a text generation method, device, electronic device and storage medium to realize efficient and accurate generation of text content.
[0005] According to one aspect of the present invention, there is provided a text generation method, the method comprising:
[0006] In response to a query request for target text content, determining a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content;
[0007] Based on the first entity, the target knowledge graph and the text generation model, determine the key entities and key entity relationships of the target text content; wherein the text generation model is used to retrieve and analyze the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content;
[0008] The target text content is generated based on the key entities, the key entity relationships and the text generation model.
[0009] According to another aspect of the present invention, there is provided a text generation device, the device comprising:
[0010] An entity determination module, configured to respond to a query request for target text content and determine a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content;
[0011] A prompt word determination module is used to determine the key entities and key entity relationships of the target text content based on the first entity, the target knowledge graph and the text generation model; wherein the text generation model is used to perform retrieval analysis on the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content;
[0012] A generation module is used to generate the target text content based on the key entity, the key entity relationship and the text generation model.
[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text generation method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the text generation method described in any embodiment of the present invention when executed.
[0018] The technical solution of the embodiment of the present invention, in response to a query request for target text content, determines a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content, that is, by parsing the first request content, the semantic intent corresponding to the query request can be accurately obtained, thereby accurately obtaining the corresponding first entity, so as to facilitate subsequent accurate retrieval of text content based on the first entity; further based on the first entity, the target knowledge graph and the text generation model, the key entity and key entity relationship of the target text content are determined; because the text generation model is used to retrieve and analyze the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content; the construction of the knowledge graph can include more semantic relationships in related fields, so as to determine the key entities and key entity relationships of the target text content based on the knowledge graph, which can greatly improve the retrieval capability and ensure that the entity semantics and entity relationships are richer, and finally, based on the key entities, key entity relationships and the text generation model, the target text content is generated, and efficient and accurate generation of text content is achieved.
[0019] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 is a flowchart of a text generation method provided according to an embodiment of the present invention;
[0022] Figure 2 is a flow chart of another text generation method provided according to an embodiment of the present invention;
[0023] Figure 3 is a flow chart of another text generation method provided according to an embodiment of the present invention;
[0024] Figure 4 is a schematic diagram of a process framework of a text generation method applicable to an embodiment of the present invention;
[0025] Figure 5is a structural schematic diagram of a text generation device provided according to an embodiment of the present invention;
[0026] Figure 6 It is a structural schematic diagram of an electronic device implementing the text generation method of the embodiment of the present invention provided according to the embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", "third", "reference", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Embodiment 1
[0030] Figure 1 A flowchart of a text generation method provided in an embodiment of the present invention. This embodiment can be applied to the situation of retrieval enhancement generation of text content. The method can be executed by a text generation device. The text generation device can be implemented in the form of hardware and / or software. The text generation device can be configured in any electronic device with network communication function.
[0031] like Figure 1 As shown, the text generation method of the present invention comprises:
[0032] S110 . In response to a query request for target text content, determine a first entity based on first request content corresponding to the query request; the first entity is a keyword of the first request content.
[0033] At present, with the explosive growth of information, how to quickly and accurately extract and integrate knowledge from massive data has become a major challenge in the current information technology field. This embodiment combines knowledge graphs with retrieval enhanced generation technology (RAG) to achieve efficient and accurate information retrieval and text content generation.
[0034] The first request content may be data for summarizing the target text content in order to obtain the target text content.
[0035] Specifically, the pre-trained language model is used to parse the first request content to determine the first entity E that can accurately represent the semantics expressed by the first request content. There can be multiple first entities. After the pre-trained language model parses the first request content, the first entity relationship R between the first entities is obtained, so that the content of the first request content can be more clearly represented. The first entity E and the first entity relationship R can be expressed as:
[0036] Among them, pre-trained language models are an important technology in the field of natural language processing. Pre-trained language models are usually based on large-scale text data for unsupervised learning. For example, pre-trained language models such as GPT-3, ELMO, and BERT.
[0037] During the pre-training phase, the model learns general knowledge and patterns of the language, including grammatical structure, semantic understanding, lexical relationships, etc.
[0038] S120. Based on the first entity, the target knowledge graph and the text generation model, determine the key entities and key entity relationships of the target text content; the text generation model is used to retrieve and analyze the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field.
[0039] The target domain is a domain associated with the input information, and the target knowledge graph is a knowledge graph associated with the first request content. The input information may be data that needs to be searched and analyzed, for example, the first entity in S110.
[0040] The text generation model includes a retrieval module and a generation module; the retrieval module is used to perform retrieval analysis on the input information based on the knowledge graph to obtain the retrieval analysis results; the generation module is used to generate text content associated with the input information based on the retrieval analysis results. The key entity is the core vocabulary for generating text content, and the key entity relationship can accurately express the semantic expression of the text content and the association between the key entity. The text generation model can be a model based on the retrieval enhanced generation technology (RAG).
[0041] Specifically, the retrieval module of the text generation model uses the first entity as the initial node for traversing each node in the target knowledge graph, compares the node similarity between the first entity and the corresponding entity on each node in the target knowledge graph, and uses the entity in the target knowledge graph whose node similarity reaches the preset node similarity as the key entity;
[0042] Furthermore, in the target knowledge graph, each key entity will be associated with entities to a certain degree. Entities whose association with key entities reaches a preset association degree will form a key entity relationship with the key entity, thereby determining the key entity relationship corresponding to each key entity.
[0043] For example, the retrieval process of the retrieval module can be expressed as E i is the key entity, R i Key entity relationship.
[0044] In this embodiment, optionally, before determining the key entities and key entity relationships of the target text content based on the first entity, the target knowledge graph and the text generation model, the method also includes: determining identification information of the first entity, determining the target knowledge graph associated with the text generation model based on the identification information, and the identification information is used to describe information of the target field.
[0045] Specifically, the retrieval module of the text generation model needs to accurately search the knowledge graph to ensure that the retrieval results obtained are accurate. Therefore, the target knowledge graph is very important. There is a corresponding relationship between the identification information of the entity and the knowledge graph. After the identification information of the first entity is determined, the corresponding target knowledge graph can be queried according to the identification information, thereby facilitating the retrieval module of the text generation model to retrieve and analyze the key entities and key entity relationships of the target text content based on the target knowledge graph.
[0046] S130: Generate target text content based on key entities, key entity relationships and a text generation model.
[0047] Specifically, the key entities and key entity relationships are synthesized through a generation module of a text generation model to obtain target text content.
[0048] Optionally, the text generation model may become inaccurate during long-term use, so it is necessary to optimize and iterate at preset time periods, including:
[0049] Collect user feedback on the generated text content, including evaluations of satisfaction, accuracy, and richness. Evaluate the text generation model based on user feedback and evaluation results, and analyze the performance bottlenecks and potential improvement points of the model. Optimize the text generation model based on the evaluation results, including improving the query strategy of the retrieval module and optimizing the model structure of the generation module. Iterate and update the optimized model and reapply it to the process of information retrieval and enhancement to continuously improve the performance and effect of the model.
[0050] The technical solution of the embodiment of the present invention, in response to a query request for target text content, determines a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content, that is, by parsing the first request content, the semantic intent corresponding to the query request can be accurately obtained, thereby accurately obtaining the corresponding first entity, so as to facilitate subsequent accurate retrieval of text content based on the first entity; further based on the first entity, the target knowledge graph and the text generation model, the key entity and key entity relationship of the target text content are determined; because the text generation model is used to retrieve and analyze the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content; the construction of the knowledge graph can include more semantic relationships in related fields, so as to determine the key entities and key entity relationships of the target text content based on the knowledge graph, which can greatly improve the retrieval capability and ensure that the entity semantics and entity relationships are richer, and finally, based on the key entities, key entity relationships and the text generation model, the target text content is generated, and efficient and accurate generation of text content is achieved.
[0051] Embodiment 2
[0052] Figure 2 This is a flowchart of another text generation method provided in an embodiment of the present invention. The technical solution of this embodiment further optimizes the process S120 in the aforementioned embodiment on the basis of the aforementioned embodiment. This embodiment can be combined with various optional solutions in one or more of the aforementioned embodiments.
[0053] like Figure 2 As shown, the text generation method of the present invention comprises:
[0054] S210 . In response to a query request for target text content, determine a first entity based on first request content corresponding to the query request; the first entity is a keyword of the first request content.
[0055] S220, determining a preset reference entity based on the first entity and a preset vector similarity; the preset vector similarity is used to describe the minimum degree of association between the first entity and the reference entity.
[0056] In this embodiment, the number of first entities obtained after parsing the first request content may be too small, so a preset vector similarity is used to collect multiple entities. The limitation of the preset vector similarity can also prevent the selected reference entity from deviating from the semantic content expressed by the first request content.
[0057] Specifically, multiple candidate entities similar to the first entity are obtained, and the candidate entities whose similarity with the first entity reaches a preset vector similarity are used as reference entities. The preset number can be determined according to actual needs. If the number of reference entities exceeds the preset number, the preset number of reference entities with the highest corresponding similarities among the reference entities are selected as the final reference entities.
[0058] S230: Determine the key entities and key entity relationships of the target text content based on the reference entity, the target knowledge graph and the text generation model.
[0059] Specifically, the retrieval module of the text generation model uses the reference entity as the initial node to traverse each node in the target knowledge graph, compares the node similarity between the reference entity and the corresponding entity on each node in the target knowledge graph, and uses the entity in the target knowledge graph whose node similarity reaches the preset node similarity as the key entity;
[0060] Furthermore, in the target knowledge graph, each reference entity will be associated with entities to a certain degree, and the entity whose association with the reference entity reaches a preset association degree will form a key entity relationship with the reference entity.
[0061] In this embodiment, the process of constructing a knowledge graph may include: acquiring unstructured text data in the target field, and performing preprocessing operations on the unstructured text data to obtain processed text data, wherein the preprocessing operations at least include data cleaning and stop word removal; using natural language processing technology and a large language model to perform text recognition on the processed text data to determine target entities and target entity relationships; further constructing a target knowledge graph based on the target entities and target entity relationships; the target entities and target entity relationships are represented in the form of triples.
[0062] As an optional but non-limiting solution, based on the reference entity, the target knowledge graph and the text generation model, the key entities and key entity relationships of the target text content are determined, including steps A1-A4:
[0063] Step A1: Based on the reference entity and the target knowledge graph, determine the reference knowledge graph corresponding to the reference entity; the reference knowledge graph is a part of the target knowledge graph.
[0064] Specifically, in the target knowledge graph, each reference entity is associated with entities to a certain extent, so a preset association range is set to limit the range of the reference knowledge graph corresponding to the reference entity selected from the target knowledge graph. The preset association range can be a range set according to actual needs, for example, setting the number of entities between the entity in the reference knowledge graph and the reference entity to no more than a preset number; further, based on the preset association range and the reference entity, the retrieval module of the text generation model selects the corresponding reference knowledge graph from the target knowledge graph.
[0065] Step A2: Determine the first key entity and the first key entity relationship of the target text content based on the reference knowledge graph.
[0066] Specifically, the entity in the reference knowledge graph is taken as the first key entity, or the entity in the reference knowledge graph whose similarity with the reference entity reaches the first reference preset similarity is taken as the first key entity, and the first key entity relationship is further established based on the association relationship of the reference knowledge graph, so that the generation module of the text generation model can be used to synthesize the first key entity and the first key entity relationship to generate the target text content.
[0067] Step A3: determine the target knowledge graph vector graph corresponding to the target knowledge graph; the target knowledge graph vector graph is a graph that represents entities and entity relationships in the target knowledge graph in the form of vectors.
[0068] Among them, the target knowledge graph vector graph and the entities in the target knowledge graph do not necessarily correspond one to one, and there may be corresponding differences. The target knowledge graph vector graph and the target knowledge graph are consistent in structural expression. For example, the first node in the target knowledge graph is the first reference entity, but the first node in the target knowledge graph vector graph is not necessarily the vector representation of the first reference entity.
[0069] In this embodiment, determining the target knowledge graph vector graph corresponding to the target knowledge graph may include: obtaining unstructured text data in the target field, and performing preprocessing operations on the unstructured text data to obtain processed text data, the preprocessing operations at least including data cleaning and stop word removal; using natural language processing technology and a large language model to perform text recognition on the processed text data to determine the target entity and the target entity relationship; further based on a preset embedding algorithm, mapping the target entity and the target entity relationship into the form of a vector to obtain the target vector entity and the target vector entity relationship; then based on the target vector entity and the target vector entity relationship, constructing a target knowledge graph vector graph; the vector difference between the two target vector entities connected by the target vector entity relationship satisfies the preset difference.
[0070] Among them, the similarity measurement methods of node and relationship embedding used in the preset embedding algorithm include but are not limited to Euclidean distance, cosine similarity and other methods.
[0071] Step A4: convert the reference entity into a vector entity, and determine the second key entity and the second key entity relationship of the target text content based on the vector entity and the target knowledge graph vector graph; the vector entity is data that represents the reference entity in the form of a vector.
[0072] Specifically, the target knowledge graph vector graph is a graph that represents entities and entity relationships in the target knowledge graph in the form of vectors. Therefore, the reference entity needs to be converted into a vector entity, so that the retrieval module of the text generation model uses the vector entity as the initial node to traverse each node in the target knowledge graph vector graph, compares the node similarity between the vector entity and the corresponding vector entity on each node in the target knowledge graph vector graph, and uses the vector entity in the target knowledge graph vector graph whose node similarity reaches the preset node vector similarity as the second key entity;
[0073] Furthermore, in the target knowledge graph vector graph, each vector entity will be associated with entities to a certain degree, and the entity and the vector entity whose association degree with each other reaches a first preset association degree will constitute a second key entity relationship, so that the second key entity and the second key entity relationship can be synthesized by the generation module of the text generation model to generate the target text content.
[0074] The technical solution of this embodiment determines the reference knowledge graph corresponding to the reference entity based on the reference entity and the target knowledge graph; determines the first key entity and the first key entity relationship of the target text content based on the reference knowledge graph, and obtains accurate first key entity and first key entity relationship, so that the target text content obtained based on the first key entity and the first key entity relationship is richer. At the same time, the target knowledge graph vector graph corresponding to the target knowledge graph is determined; the target knowledge graph vector graph is a graph that represents entities and entity relationships in the target knowledge graph in the form of vectors; the reference entity is converted into a vector entity, and the second key entity and the second key entity relationship of the target text content are determined based on the vector entity and the target knowledge graph vector graph; the vector entity is data that represents the reference entity in the form of a vector, that is, the accurate second key entity and the second key entity relationship are obtained from the dimension represented by the vector, so that the target text content obtained based on the second key entity and the second key entity relationship is richer.
[0075] In this embodiment, optionally, based on the first entity, the target knowledge graph and the text generation model, determining the key entities and key entity relationships of the target text content may include: taking the first key entity and the second key entity as the first reference key entity; determining the first similarity between the first entity and the first reference key entity; and determining the key entities and key entity relationships of the target text content based on the comparison result of the first similarity and the first preset similarity. Specifically, taking the first reference key entity corresponding to the first similarity greater than the first preset similarity as the key entity of the target text content, and constructing the key entity relationship of the target text content based on the first key entity relationship and the second key entity relationship.
[0076] The technical solution of this embodiment obtains more accurate key entities and key entity relationships of the target text content by screening the first key entity and the second key entity according to the first preset similarity.
[0077] S240: Generate target text content based on key entities, key entity relationships and a text generation model.
[0078] The technical solution of the embodiment of the present invention responds to a query request for target text content, determines a first entity based on the first request content corresponding to the query request; the first entity is a keyword of the first request content; further determines a preset reference entity based on the first entity and the preset vector similarity; because the preset vector similarity is used to describe the minimum degree of association between the first entity and the reference entity, it avoids the inaccuracy and lack of depth of the target text content finally generated due to too few entities; then based on the reference entity, the target knowledge graph and the text generation model, determines the key entities and key entity relationships of the target text content, that is, through the retrieval of the target knowledge graph by the text generation model, more entities that can represent the first request content can be obtained, that is, more in-depth key entities and key entity relationships can be obtained, so that finally based on the key entities, the key entity relationships and the text generation model, more accurate target text content is generated.
[0079] Embodiment 3
[0080] Figure 3 This is a flowchart of another text generation method provided in an embodiment of the present invention. The technical solution of this embodiment further optimizes the process S120 in the aforementioned embodiment on the basis of the aforementioned embodiment. This embodiment can be combined with various optional solutions in one or more of the aforementioned embodiments.
[0081] like Figure 2 As shown, the text generation method of the present invention comprises:
[0082] S310: In response to a query request for target text content, determine a first entity based on first request content corresponding to the query request; the first entity is a keyword of the first request content.
[0083] S320, determining a preset reference entity based on the first entity and a preset vector similarity; the preset vector similarity is used to describe the minimum degree of association between the first entity and the reference entity.
[0084] S330. Based on the reference entity and the target knowledge graph, determine the reference knowledge graph corresponding to the reference entity, and determine the first key entity and the first key entity relationship of the target text content based on the reference knowledge graph; the reference knowledge graph is a part of the target knowledge graph.
[0085] For example, the reference knowledge graph is as follows Figure 4 The connected subgraph of the retrieved knowledge graph is shown.
[0086] S340. Determine the target knowledge graph vector graph corresponding to the target knowledge graph, convert the reference entity into a vector entity, and determine the second key entity and the second key entity relationship of the target text content based on the vector entity and the target knowledge graph vector graph; the target knowledge graph vector graph is a graph that represents entities and entity relationships in the target knowledge graph in the form of vectors.
[0087] A vector entity is data that represents a reference entity in the form of a vector.
[0088] For example, the relationship between the second key entity and the second key entity is as follows Figure 4 The nodes and relationships of the retrieved knowledge graph are shown.
[0089] S350, determining a second similarity between the reference entity and the target data block in the vector database, and determining a third key entity and a third key entity relationship of the target text content based on a comparison result of the second similarity and a second preset similarity, wherein the vector database stores a target data block corresponding to the target domain, the target data block includes at least one entity, and the target data block is used to describe the association between entities.
[0090] In this embodiment, constructing a target data block in a vector database may include: acquiring unstructured text data in a target field, and performing a preprocessing operation on the unstructured text data to obtain processed text data, wherein the preprocessing operation at least includes data cleaning and stop word removal; performing block processing on the processed text data according to preset block requirements to obtain at least one reference data block; based on a preset embedding algorithm, mapping the reference data block into a vector form to obtain a target data block, and storing the target data block in the vector database.
[0091] Specifically, the retrieval module of the text generation model takes the target data block corresponding to the second similarity greater than the second preset similarity as the candidate data block, takes the entity in the candidate data block as the third key entity, and constructs the third key entity relationship according to the entity association relationship in the candidate data block. Figure 4 As shown, the candidate data block is the retrieved knowledge block. Further, the first key entity, the second key entity and the third key entity can be directly used to generate the target text content through the generation module of the text generation model.
[0092] S360: Determine key entities and key entity relationships of the target text content based on the first key entity, the second key entity, and the third key entity.
[0093] In this embodiment, the preset constraint condition is used to describe the semantic expression scope of the target text content, and may be, for example, a constraint combining context information and a diversity constraint.
[0094] Specifically, determining the key entities and key entity relationships of the target text content based on the first key entity, the second key entity and the third key entity can include: taking the first key entity, the second key entity and the third key entity as the second reference key entity; determining the third similarity between the first entity relationship and the second reference key entity, and determining the first comparison result based on the third similarity and the third preset similarity; determining the preset constraint conditions based on the first request content, and determining the key entities and key entity relationships of the target text content based on the first comparison result and the preset constraint conditions.
[0095] S370: Generate target text content based on key entities, key entity relationships and a text generation model.
[0096] The technical solution of this embodiment, after obtaining the first key entity, the second key entity and the third key entity, determines the key entities and key entity relationships of the target text content based on the first key entity, the second key entity and the third key entity, that is, by further screening the first key entity, the second key entity and the third key entity, the accuracy of the key entities and key entity relationships is ensured, so that based on the key entities, key entity relationships and text generation model, more in-depth target text content can be generated.
[0097] Embodiment 4
[0098] Figure 5 A structural schematic diagram of a text generation device provided in an embodiment of the present invention. This embodiment can be applied to the situation of performing retrieval enhancement generation on text content. The text generation device can be implemented in the form of hardware and / or software, and the text generation device can be configured in any electronic device with network communication function.
[0099] like Figure 5 As shown, the text generation device of the present invention comprises:
[0100] The entity determination module 410 is used to respond to a query request for target text content and determine a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content;
[0101] The prompt word determination module 420 is used to determine the key entities and key entity relationships of the target text content based on the first entity, the target knowledge graph and the text generation model; wherein the text generation model is used to perform retrieval analysis on the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content;
[0102] The generation module 430 is used to generate the target text content based on the key entities, the key entity relationships and the text generation model.
[0103] Based on the above embodiment, optionally, the text generation model includes a retrieval module and a generation module; the retrieval module is used to perform retrieval analysis on the input information based on the knowledge graph to obtain retrieval analysis results; the generation module is used to generate text content associated with the input information based on the retrieval analysis results.
[0104] Based on the above embodiment, optionally, the device further includes a spectrum matching module, which is used to:
[0105] Determine identification information of the first entity, and determine a target knowledge graph associated with the text generation model based on the identification information, wherein the identification information is used to describe information of a target domain.
[0106] Based on the above embodiment, optionally, the prompt word determination module includes:
[0107] A reference entity determination unit, configured to determine a preset number of reference entities based on the first entity and a preset vector similarity; the preset vector similarity is used to describe a minimum degree of association between the first entity and the reference entity;
[0108] An entity determination unit is used to determine key entities and key entity relationships of target text content based on the reference entity, the target knowledge graph and the text generation model.
[0109] Based on the above embodiment, optionally, the entity determination unit is configured to:
[0110] Based on the reference entity and the target knowledge graph, determine a reference knowledge graph corresponding to the reference entity; the reference knowledge graph is a part of the target knowledge graph;
[0111] Determine the first key entity and the first key entity relationship of the target text content based on the reference knowledge graph;
[0112] Determine a target knowledge graph vector graph corresponding to the target knowledge graph; the target knowledge graph vector graph is a graph representing entities and entity relationships in the target knowledge graph in the form of vectors;
[0113] The reference entity is converted into a vector entity, and based on the vector entity and the knowledge graph vector graph, the second key entity and the second key entity relationship of the target text content are determined; the vector entity is data representing the reference entity in the form of a vector.
[0114] Based on the above embodiment, optionally, the prompt word determination module includes a first key entity determination unit, which is used to:
[0115] Taking the first key entity and the second key entity as first reference key entities;
[0116] determining a first similarity between the first entity relationship and a first reference key entity;
[0117] Based on the comparison result of the first similarity and the first preset similarity, key entities and key entity relationships of the target text content are determined.
[0118] Based on the above embodiment, optionally, the prompt word determination module includes a second key entity determination unit, which is used to:
[0119] Determine a second similarity between the reference entity and a target data block in a vector database; the vector database stores a target data block corresponding to the target domain, the target data block includes at least one entity, and the target data block is used to describe the association between entities;
[0120] Based on the comparison result of the second similarity and the second preset similarity, determining the third key entity and the third key entity relationship of the target text content;
[0121] Taking the first key entity, the second key entity and the third key entity as second reference key entities;
[0122] Determine a third similarity between the first entity relationship and a second reference key entity, and determine a first comparison result based on the third similarity and a third preset similarity;
[0123] Preset constraints are determined based on the first request content, and key entities and key entity relationships of the target text content are determined based on the first comparison result and the preset constraints; the preset constraints are used to describe the semantic expression scope of the target text content.
[0124] The text generation device provided in the embodiment of the present invention can execute the text generation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0125] The acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations and do not violate public order and good morals.
[0126] Embodiment 5
[0127] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0128] Figure 6 A schematic diagram of the structure of an electronic device that can be used to implement the text generation method of an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0129] like Figure 6 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0130] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0131] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a text generation method.
[0132] In some embodiments, the text generation method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the text generation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the text generation method in any other appropriate manner (e.g., by means of firmware).
[0133] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0134] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0135] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, 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 foregoing.
[0136] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0137] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0138] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0139] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0140] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A text generation method, characterized in that: The method comprises: In response to a query request for target text content, determining a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content; Based on the first entity, the target knowledge graph and the text generation model, determine the key entities and key entity relationships of the target text content; wherein the text generation model is used to retrieve and analyze the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content; The target text content is generated based on the key entities, the key entity relationships and the text generation model.
2. The method according to claim 1, characterized in that The text generation model includes a retrieval module and a generation module; the retrieval module is used to perform retrieval analysis on the input information based on the knowledge graph to obtain retrieval analysis results; the generation module is used to generate text content associated with the input information based on the retrieval analysis results.
3. The method according to claim 1, characterized in that: Before determining the key entities and key entity relationships of the target text content based on the first entity, the target knowledge graph and the text generation model, the method further includes: Determine identification information of the first entity, and determine a target knowledge graph associated with the text generation model based on the identification information, wherein the identification information is used to describe information of a target domain.
4. The method according to claim 1, characterized in that: Based on the first entity, the target knowledge graph and the text generation model, key entities and key entity relationships of the target text content are determined, including: Determine a preset reference entity based on the similarity between the first entity and a preset vector; the preset vector similarity is used to describe the minimum degree of association between the first entity and the reference entity; Based on the reference entity, the target knowledge graph and the text generation model, key entities and key entity relationships of the target text content are determined.
5. The method according to claim 4, characterized in that Based on the reference entity, the target knowledge graph and the text generation model, key entities and key entity relationships of the target text content are determined, including: Based on the reference entity and the target knowledge graph, determine a reference knowledge graph corresponding to the reference entity; the reference knowledge graph is a part of the target knowledge graph; Determine the first key entity and the first key entity relationship of the target text content based on the reference knowledge graph; Determine a target knowledge graph vector graph corresponding to the target knowledge graph; the target knowledge graph vector graph is a graph representing entities and entity relationships in the target knowledge graph in the form of vectors; The reference entity is converted into a vector entity, and based on the vector entity and the target knowledge graph vector graph, the second key entity and the second key entity relationship of the target text content are determined; the vector entity is data representing the reference entity in the form of a vector.
6. The method according to claim 5, characterized in that Based on the first entity, the target knowledge graph and the text generation model, key entities and key entity relationships of the target text content are determined, including: Taking the first key entity and the second key entity as first reference key entities; determining a first similarity between the first entity and the first reference key entity; Based on the comparison result of the first similarity and the first preset similarity, key entities and key entity relationships of the target text content are determined.
7. The method according to claim 5, characterized in that Based on the first entity, the target knowledge graph and the text generation model, key entities and key entity relationships of the target text content are determined, including: Determine a second similarity between the reference entity and a target data block in a vector database; the vector database stores a target data block corresponding to the target domain, the target data block includes at least one entity, and the target data block is used to describe the association between entities; Based on the comparison result of the second similarity and the second preset similarity, determining the third key entity and the third key entity relationship of the target text content; Taking the first key entity, the second key entity and the third key entity as second reference key entities; Determine a third similarity between the first entity relationship and a second reference key entity, and determine a first comparison result based on the third similarity and a third preset similarity; Preset constraints are determined based on the first request content, and key entities and key entity relationships of the target text content are determined based on the first comparison result and the preset constraints; the preset constraints are used to describe the semantic expression scope of the target text content.
8. A text generation device, characterized in that: The device comprises: An entity determination module, configured to respond to a query request for target text content and determine a first entity based on a first request content corresponding to the query request; the first entity is a keyword of the first request content; A prompt word determination module is used to determine the key entities and key entity relationships of the target text content based on the first entity, the target knowledge graph and the text generation model; wherein the text generation model is used to perform retrieval analysis on the input information based on the knowledge graph to generate text content associated with the input information; the knowledge graph is a graph used to describe different entities and different entity relationships corresponding to the target field; the target field is a field associated with the input information; the target knowledge graph is a knowledge graph associated with the first request content; A generation module is used to generate the target text content based on the key entity, the key entity relationship and the text generation model.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text generation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the text generation method according to any one of claims 1 to 7 when executed.
Citation Information
Cited By
Image description text generation method based on large language model
CN119227816A
Text reply method and device, electronic equipment and storage medium
CN119884322A
