Language output method, system, device and storage medium based on knowledge graph

Through the language output method based on knowledge graph, the problem of high resource demand and difficulty in understanding complex concepts of large language models in question and answer in professional subject areas is solved, more accurate and targeted answer generation is achieved, and the application effect is improved.

CN118332134BActive Publication Date: 2024-09-10HUBEI UNIV OF ECONOMICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410692008.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2024-09-10
Estimated Expiration
2044-05-31

AI Technical Summary

Technical Problem

Large language models have problems such as high hardware resource requirements, high computing resource requirements, and difficulty in accurately understanding complex concepts in question answering in professional subject areas, which affects their application effects.

Method used

Using the language output method based on the knowledge graph, by preprocessing and segmenting the document, extracting the summary and performing vector encoding, the vector database and knowledge graph are constructed. The user inputs the vector search index, obtains a summary of similar nodes, and inputs a large language model to generate Answer.

Benefits of technology

Significantly improves the applicability and credibility of large-scale language models in professional subject areas, provides more comprehensive and accurate answers, measures the importance of key sentences through professional vocabulary and sentence relationships, and contains contextual information, enhancing the pertinence and accuracy of answers. accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118332134B
    Figure CN118332134B
Patent Text Reader

Abstract

The present application discloses a language output method, system, device and storage medium based on a knowledge graph, which belongs to the field of information retrieval technology. The present application first pre-processes and segments the background documents, extracts summaries from the fragments, and vector encodes the summaries; then constructs a vector database and a knowledge graph based on the summaries; vector encodes the user input to obtain an input vector, and searches for the index of the corresponding vector in the vector database based on the input vector; then obtains a node from the knowledge graph according to the index, and uses the node and multiple nodes with the highest similarity to the node as hit nodes; finally, inputs the summary stored in the hit node into a large language model to obtain the final output. The present application introduces background documents in professional disciplines in the form of knowledge graphs and vector databases to enhance the input of the large language model, so that the large language model can provide more comprehensive and accurate answers and solutions in a more targeted manner.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of information retrieval technology, and more specifically, relates to a language output method, system, device and storage medium based on a knowledge graph. Background Art

[0002] In recent years, large language models (LLMs) have achieved impressive results in a variety of natural language processing tasks and demonstrated a number of emergent capabilities. Autoregressive large language models such as InstructGPT, ChatGPT, and GPT4 have demonstrated outstanding natural language understanding and generation capabilities in understanding, obeying, and responding to human instructions through pre-training, command fine-tuning, RLHF, and other technologies. This makes them potential general task solvers and has a profound impact on natural language question answering.

[0003] Answers to professional questions usually involve complex theoretical systems, practical experience, and judgment. These factors make it difficult to answer professional questions through simple rules or algorithms. There are still many problems in directly applying large language models to question and answer in professional disciplines. On the one hand, the use of large language models to answer questions in professional disciplines requires a lot of hardware resources; training and tuning these huge models requires a lot of computing power, which places extremely high demands on computing resources. This makes it extremely difficult to use large models for training in vertical disciplines. On the other hand, when faced with professional discipline questions, large language models often find it difficult to accurately understand and explain complex concepts and situations, which affects their application in professional disciplines. Summary of the invention

[0004] In response to the above defects or improvement needs of the prior art, the present application provides a language output method, system, device and storage medium based on a knowledge graph, which aims to solve the technical problem that the existing large language model is not effective in question and answering in professional subject areas.

[0005] To achieve the above objectives, in a first aspect, the present application provides a language output method based on a knowledge graph, comprising:

[0006] Preprocessing and segmenting the document, setting a unique identifier for each segmented segment, extracting a summary from the segment, and vector encoding the summary;

[0007] Using the identifier of the segment as an index, constructing a vector database based on the encoded vector;

[0008] A knowledge graph is constructed with the identifiers of the fragments as nodes and the similarities between the fragments as edges, and the summaries of the fragments are stored in the nodes;

[0009] Performing vector encoding on the user input to obtain an input vector, and searching for an index of a corresponding vector in the vector database based on the input vector;

[0010] Obtain a node from the knowledge graph according to the index, and use the node and multiple nodes with the highest similarity to the node as hit nodes;

[0011] The summary stored in the hit node is input into the large model to obtain the final output.

[0012] Preferably, the document is preprocessed and segmented, specifically: the document is cleaned to remove unnecessary information in the document; then the document is segmented according to a preset size, and the document is segmented into multiple segments of the same size.

[0013] Preferably, extracting a summary from the fragment is specifically:

[0014] The segment is divided into a plurality of sentences, and a weighted undirected graph is constructed with the sentences as nodes and the relationships between the sentences as edge weights;

[0015] Iteratively calculate the importance of each node, where the importance is determined by the importance of all adjacent nodes and the weight of the edge;

[0016] The sentence with the highest importance is then the summary of the fragment.

[0017] Preferably, the node has an initial importance, which is equal to the number of professional words in the node plus a preset baseline importance.

[0018] Preferably, vector encoding is performed, specifically: a sentence is divided into multiple words; a word vector is composed of a word, a word position, and a word paragraph; and an encoded sentence vector is composed of all word vectors.

[0019] Preferably, searching the index of the corresponding vector in the vector database based on the input vector is specifically:

[0020] Search the vector database to see if there is a vector identical to the input vector. If so, output the index of the vector. If not, calculate the similarity between all vectors in the vector database and the input vector, and output the index of the vector with the highest similarity.

[0021] Preferably, the summary stored in the hit node is input into the large language model, specifically:

[0022] The summary and preset text stored in the hit node are input into a large language model; the preset text is generated after the corresponding user input content is input into the pre-trained language model.

[0023] In the second aspect, the present application provides a language output system based on a knowledge graph, comprising:

[0024] A document encoding module is used to pre-process and segment the document, set a unique identifier for each segmented segment, extract a summary from the segment, and perform vector encoding on the summary;

[0025] A database construction module, used to construct a vector database based on the encoded vector using the identifier of the fragment as an index;

[0026] A knowledge graph construction module, used to construct a knowledge graph with the identifiers of the fragments as nodes and the similarities between the fragments as edges, wherein the nodes store summaries of the fragments;

[0027] An input encoding module, used to perform vector encoding on the user input to obtain an input vector, and search for an index of a corresponding vector in the vector database based on the input vector;

[0028] An input retrieval module is used to obtain a node from the knowledge graph according to the index, and take the node and multiple nodes with the highest similarity to the node as hit nodes;

[0029] The output module is used to input the summary stored in the hit node into the large language model to obtain the final output.

[0030] In a third aspect, the present application provides an electronic device, comprising: a memory for storing programs; a processor for executing the programs stored in the memory, when the program stored in the memory is executed, the processor is used to execute the method described in the first aspect or any possible implementation of the first aspect.

[0031] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method described in the first aspect or any possible implementation of the first aspect.

[0032] In general, the above technical solutions conceived by this application have the following beneficial effects compared with the prior art:

[0033] (1) This application can significantly improve the applicability and credibility of large language models in professional disciplines; by introducing background documents in professional disciplines in the form of knowledge graphs and vector databases to enhance the input of large language models, the large language models can provide more comprehensive and accurate answers and solutions in a more targeted manner.

[0034] (2) This application uses the relationship between professional vocabulary and sentences in the professional discipline field as an indicator to measure the importance of key sentences in the background document, and thus selects key sentences from the document fragment as the summary of the document fragment, so that the summary can be more appropriate for the description of the professional discipline field.

[0035] (3) The vector encoding of the abstract in this application includes the position of each word in the abstract and the position of the abstract, thereby also including the contextual information of the background document. As a result, the vector contains more professional subject background information. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 It is a flow chart of a language output method based on knowledge graph provided in an embodiment of the present application;

[0037] Figure 2 It is a schematic diagram of the composition of a language output electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0039] Next, the technical solutions provided in the embodiments of the present application are introduced.

[0040] like Figure 1 As shown, the embodiment of the present application specifically includes the following steps:

[0041] (1) Collect knowledge documents in professional disciplines as background technical documents. Since these documents are unstructured documents, the background documents need to be preprocessed and segmented, and unique identifiers are set for each segmented fragment:

[0042] (11) Clean the background documents and remove unnecessary information in the documents, such as formatting, special characters, repeated tags, stop words, non-standard formats, spaces, etc., to make the data more suitable for further analysis and processing.

[0043] (12) After the document is cleaned, it is divided into multiple segments according to the specified size. For example, the segment size is set to 512 characters, which means that each 512 characters constitutes a document segment.

[0044] Those skilled in the art will appreciate that punctuation marks in a document may also be identified, and specific punctuation marks may be used as identification marks for dividing document segments.

[0045] (2) Find the key sentences from each document fragment as the summary of the fragment:

[0046] (21) The document fragments are divided into multiple sentences, and a weighted undirected graph is constructed with each sentence as a node and the relationship between sentences as the weight of the edge. The relationship between sentences can be the similarity between sentences or the degree of association between sentences. The cosine similarity or Euclidean distance can be used to measure the similarity between sentences.

[0047] (22) Each node is assigned an initial importance, which is set to 1. Alternatively, the initial importance is determined based on the number of professional vocabulary in the node sentence plus the baseline importance. For example, if the number of professional vocabulary in the sentence of node 1 is 2 and its baseline importance is set to 1, the initial importance of node 1 is 3. If the number of professional vocabulary in the sentence of node 2 is 0 and its baseline importance is set to 1, the initial importance of node 2 is 1. A professional vocabulary list is preset, and if a word in a sentence hits the professional vocabulary list, the word is a professional vocabulary.

[0048] (23) Iteratively calculating the importance of each node, where the importance is determined by the importance of all adjacent nodes and the weight of the edge;

[0049] (24) After iterative calculation, for example, setting the iterative calculation to be 3 times, after completing 3 importance calculations, the sentence with the highest importance is statistically obtained. This sentence is the key sentence of the fragment, that is, the summary of the fragment.

[0050] Those skilled in the art will appreciate that the TextRank algorithm may also be used to perform sentence-level summarization on each segment.

[0051] (3) Encode the abstract into vectors and build a vector database based on the vectors;

[0052] (31) First, the abstract is segmented;

[0053] (32) Record the word's location and paragraph;

[0054] (33) The word, the word position, and the paragraph in which the word is located are combined into a word vector, and all the word vectors in the abstract are combined into a summary vector;

[0055] Those skilled in the art will appreciate that other existing vector encoding methods may also be used to perform vector encoding on sentences.

[0056] (34) A vector database is constructed using the unique identifier of the fragment where the abstract is located as the database index to store the vectors of all fragment abstracts.

[0057] (4) A knowledge graph is constructed with the identifiers of the fragments as nodes and the similarities between the fragments as edges, and the summaries of the fragments are stored in the nodes.

[0058] (41) We can set a similarity threshold, such as 0.5, and remove the edges below this similarity threshold. This is to make the entire knowledge graph more concise. Otherwise, when searching in the subsequent parts, one document will return many similar document fragments.

[0059] (5) performing vector encoding on the user input to obtain an input vector, and searching for an index of a corresponding vector in the vector database based on the input vector;

[0060] (51) First, the user input content is input into the pre-trained language model to generate a preset text. The pre-trained language model determines the input text as a question type, a supplementary explanation type, a scenario type, etc. based on the user input content and tone, and selects the corresponding preset text stored in the system in advance;

[0061] (52) Perform vector encoding on the user input to obtain an input vector, and search in the vector database to see whether there is a vector identical to the input vector. If so, output the index of the vector; if not, calculate the similarity between all vectors in the vector database and the input vector, and output the index of the vector with the highest similarity.

[0062] (6) Obtain a node from the knowledge graph according to the index, and use the node and multiple nodes with the highest similarity to the node as hit nodes.

[0063] (7) The summary stored in the hit node and the preset text together constitute the input of the large language model to obtain the final output.

[0064] This application also implements a language output system based on knowledge graph.

[0065] It should be understood that the above-mentioned system is used to execute the methods in the above-mentioned embodiments. The implementation principles and technical effects of the corresponding modules in the system are similar to those described in the above-mentioned methods. The working process of the system can refer to the corresponding process in the above-mentioned method and will not be repeated here.

[0066] Based on the method in the above embodiment, the embodiment of the present application provides an electronic device, such as Figure 2 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the method in the above embodiment.

[0067] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the outstanding performance of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application.

[0068] Based on the method in the above embodiment, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method in the above embodiment.

[0069] Based on the method in the above embodiment, an embodiment of the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the method in the above embodiment.

[0070] It is understood that the processor in the embodiments of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.

[0071] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.

[0072] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a storage medium or transmitted through the storage medium. The computer instructions may be transmitted from a website site, a computer, a server or a data center to another website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.

[0073] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.

[0074] The above content is easily understood by those skilled in the art. The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims

1. A language output method based on knowledge graph, It is characterized in that include: Preprocessing and segmenting the document, setting a unique identifier for each segmented segment, extracting a summary from the segment, and vector encoding the summary; Using the identifier of the segment as an index, constructing a vector database based on the encoded vector; A knowledge graph is constructed with the identifiers of the fragments as nodes and the similarities between the fragments as edges, and the summaries of the fragments are stored in the nodes; Performing vector encoding on the user input to obtain an input vector, and searching for an index of a corresponding vector in the vector database based on the input vector; Obtain a node from the knowledge graph according to the index, and use the node and multiple nodes with the highest similarity to the node as hit nodes; Inputting the summary stored in the hit node into the large model to obtain the final output; Extract a summary from the snippet, specifically: The segment is divided into a plurality of sentences, and a weighted undirected graph is constructed with the sentences as nodes and the relationships between the sentences as edge weights; Iteratively calculate the importance of each node, where the importance is determined by the importance of all adjacent nodes and the weights of their edges; The sentence with the highest importance is the summary of the fragment; The node has an initial importance, which is equal to the number of professional words in the node plus a preset baseline importance.

2. The language output method according to claim 1, It is characterized in that The summary is vector-encoded, specifically: the sentence is divided into multiple words; the word vector is composed of the word, the word position, and the word paragraph; and the encoded sentence vector is composed of all word vectors.

3. The language output method according to claim 1, It is characterized in that Find the index of the corresponding vector in the vector database based on the input vector, specifically: Search the vector database to see if there is a vector identical to the input vector. If so, output the index of the vector. If not, calculate the similarity between all vectors in the vector database and the input vector, and output the index of the vector with the highest similarity.

4. The language output method according to claim 1, It is characterized in that The summary stored in the hit node is input into the large language model, specifically: The summary and preset text stored in the hit node are input into a large language model; the preset text is generated after the corresponding user input content is input into the pre-trained language model.

5. The language output method according to claim 1, It is characterized in that The document is preprocessed and segmented, specifically: the document is cleaned to remove unnecessary information in the document; then the document is segmented according to a preset size, and the document is segmented into multiple segments of the same size.

6. A language output system based on knowledge graph, It is characterized in that It adopts a language output method based on knowledge graph as described in claim 1, including: A document encoding module is used to pre-process and segment the document, set a unique identifier for each segmented segment, extract a summary from the segment, and perform vector encoding on the summary; A database construction module, used to construct a vector database based on the encoded vector using the identifier of the fragment as an index; A knowledge graph construction module, used to construct a knowledge graph with the identifiers of the fragments as nodes and the similarities between the fragments as edges, wherein the nodes store summaries of the fragments; An input encoding module, used to perform vector encoding on the user input to obtain an input vector, and search for an index of a corresponding vector in the vector database based on the input vector; An input retrieval module is used to obtain a node from the knowledge graph according to the index, and take the node and multiple nodes with the highest similarity to the node as hit nodes; The output module is used to input the summary stored in the hit node into the large language model to obtain the final output.

7. An electronic device, It is characterized in that include: Memory for storing computer programs; A processor, configured to execute the program stored in the memory. When the program stored in the memory is executed, the processor is configured to execute the method according to any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program runs on a processor, the processor is caused to execute the method according to any one of claims 1 to 5.