CN116821301A - Knowledge graph-based problem response method, device, medium and computer equipment - Google Patents

Knowledge graph-based problem response method, device, medium and computer equipment Download PDF

Info

Publication number
CN116821301A
CN116821301A CN202310795311.0A CN202310795311A CN116821301A CN 116821301 A CN116821301 A CN 116821301A CN 202310795311 A CN202310795311 A CN 202310795311A CN 116821301 A CN116821301 A CN 116821301A
Authority
CN
China
Prior art keywords
query
vector
language model
attribute
type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310795311.0A
Other languages
Chinese (zh)
Inventor
王俊
侯昶宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202310795311.0A priority Critical patent/CN116821301A/en
Publication of CN116821301A publication Critical patent/CN116821301A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/332Query formulation
    • G06F16/3329Natural language query formulation or dialogue systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/3331Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/36Creation of semantic tools, e.g. ontology or thesauri
    • G06F16/367Ontology
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Human Computer Interaction (AREA)
  • Artificial Intelligence (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Animal Behavior & Ethology (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a problem response method, device, medium and computer equipment based on a knowledge graph, and relates to the technical field of artificial intelligence and digital medical treatment. The method comprises the following steps: receiving a natural language question input by a user, and converting the natural language question into a question vector by using a pre-trained target language model as an encoder; classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector; converting the problem vector into a graph database query statement based on element information of the problem vector by using the target language model as a decoder; and executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder. The method can improve the accuracy of the problem response, and especially improve the accuracy of the problem response in the field of medical profession.

Description

Knowledge graph-based problem response method, device, medium and computer equipment
Technical Field
The invention relates to the technical field of artificial intelligence and digital medical treatment, in particular to a problem response method, device, medium and computer equipment based on a knowledge graph.
Background
Knowledge Graph (KG) is a data model for representing and storing structured and semi-structured Knowledge, and generally adopts a form of a triplet of Entity-relationship-Entity (ERE), which can provide abundant semantic information and reasoning capability. By using the established knowledge graph, related entities and relations can be searched in the knowledge graph according to natural language questions presented by a user, and answers conforming to the user intention are returned, so that knowledge question answering (Knowledge Base Question Answering, KBQA) in the professional field, for example, knowledge question answering in the medical professional field and the like are realized.
In the prior art, manually written rules are mainly used for classifying and analyzing the questions, templates are used for generating query sentences and answers, or statistical models are used for classifying and analyzing the questions, grammar analysis is used for generating the query sentences, and templates are used for generating answers. However, natural language questions have diversity, complexity and ambiguity, existing rules or statistical models are difficult to cover all possible situations in the natural language questions, misjudgment or missed judgment of the questions is easy to occur, and in addition, existing ways of generating query sentences or answers based on templates or grammar analysis are also difficult to process complex, multi-hop or unstructured natural language questions, and smooth, coherent and logical answers are difficult to generate.
Disclosure of Invention
In view of the above, the application provides a knowledge-graph-based question answering method, a device, a medium and a computer device, which mainly aim to solve the technical problems that a question answering system based on a knowledge graph is prone to wrong judgment and missed judgment, and generated query sentences and answers are not accurate enough and smooth enough.
According to a first aspect of the present application, there is provided a knowledge-graph-based problem response method, the method comprising:
receiving a natural language question input by a user, and converting the natural language question into a question vector by using a pre-trained target language model as an encoder;
classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector;
converting the problem vector into a graph database query statement based on element information of the problem vector by using the target language model as a decoder;
executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder.
According to a second aspect of the present invention, there is provided a knowledge-graph-based problem response apparatus, comprising:
the problem vector conversion module is used for receiving a natural language problem input by a user, and converting the natural language problem into a problem vector by using a pre-trained target language model as an encoder;
the problem classification analysis module is used for classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector;
the query statement generation module is used for converting the problem vector into a graph database query statement based on element information of the problem vector by using the target language model as a decoder;
and the query result conversion module is used for executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder.
According to a third aspect of the present invention, there is provided a storage medium having stored thereon a computer program which, when executed by a processor, implements the above-described knowledge-graph-based problem response method.
According to a fourth aspect of the present invention, there is provided a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above-mentioned knowledge-graph-based problem response method when executing the program.
The invention provides a question response method, a device, a storage medium and computer equipment based on a knowledge graph, which are characterized in that firstly, a pre-trained target language model is used as an encoder to convert natural language questions input by a user into question vectors, then the question vectors are classified and analyzed by the target language model to obtain various element information such as question types, entity sets, relation sets, attribute sets and the like of the question vectors, the target language model is further used as a decoder to convert the question vectors into query sentences of a graph database based on the element information of the question vectors, finally, the query sentences of the graph database are executed in the pre-established knowledge graph to obtain query results, and the target language model is used as the decoder to convert the query results into natural language answers. The method utilizes the language model to obtain query sentences and answers to questions for natural language understanding and generating capacity, can effectively cover the possible occurrence of natural language in various contexts, and effectively avoids misjudgment or missed judgment of the questions. In addition, the language model is used for classifying and analyzing the natural language questions, generating query sentences and generating natural language answers, so that the accuracy of query sentence conversion can be effectively improved, the generated graph database query sentences and the natural language questions have higher matching degree, and the generated natural language answers are more accurate, smooth, consistent and logical.
The foregoing description is only an overview of the present application, and is intended to be implemented in accordance with the teachings of the present application in order that the same may be more clearly understood and to make the same and other objects, features and advantages of the present application more readily apparent.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
fig. 1 shows a flow diagram of a problem response method based on a knowledge graph according to an embodiment of the present application;
fig. 2 is a schematic flow chart of another method for answering a question based on a knowledge graph according to an embodiment of the present application;
fig. 3 shows a schematic structural diagram of a problem response device based on a knowledge graph according to an embodiment of the present application;
fig. 4 shows a schematic structural diagram of another problem response device based on a knowledge graph according to an embodiment of the present application.
Detailed Description
The application will be described in detail hereinafter with reference to the drawings in conjunction with embodiments. It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other.
In one embodiment, as shown in fig. 1, a method for answering a question based on a knowledge graph is provided, and the method is applied to a computer device such as a server, for example, and includes the following steps:
101. and receiving the natural language questions input by the user, and converting the natural language questions into question vectors by using the pre-trained target language model as an encoder.
The language model is a model which is trained through a large number of language samples and can convert natural language into vector representation, then the vector representation is converted into another section of natural language with a certain mapping relation with the input language, the former process is called coding, and the latter conversion process is called decoding. Based on this, the language model is composed of at least two parts, an encoder and a decoder. In this embodiment, the target language model may be a language model that has been used in the open at present, such as ChatGLM, BERT, GPT-3, XLNet, MOSS, chatYuan, baiChuan, OPT, LLAMA, etc., or may be a language model that is optimized for parameters according to a ternary data set corresponding to a knowledge graph. It can be understood that the above multiple language models can be encoded and decoded, and parameters can be optimized, however, different language models have different performances and characteristics, so that an appropriate language model needs to be selected for application according to a specific application scenario and data set, and the embodiment does not specifically limit the type of the language model.
Specifically, the user may input a natural language question to be asked, such as "what is why a vaccinia is left on the face", "what is a specific medicine for cold", etc., through the client, and then the client may send the natural language question input by the user to the server, and the server may input the natural language question to the encoder of the pre-trained target language model, so as to generate a question vector corresponding to the natural language question through the encoder. The embodiment can facilitate the subsequent multi-task classification, query sentence generation, answer generation and other operations on the natural language questions by converting the natural language questions into the question vectors.
102. And classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector.
The question type refers to a splicing mode of each element related to the natural language question, and generally comprises an attribute query type and a relation query type. The attribute query type is composed of an entity and an attribute, for example, a natural language problem of what cause is the acne on the face is an attribute query type, the entity is the acne on the face, the attribute is the cause, the relationship query type is composed of an entity and a relationship, for example, a natural language problem of what specific medicine for treating cold is, the entity is the cold, and the relationship is the relationship between medicine and diseases. It should be noted that the question types of the same question vector are sometimes not single, but may contain multiple question types and/or contain multiple same question types. For example, the natural language question "what characterizes the cold, if it should take what medicine" belongs to the question containing both the attribute query type and the relationship query type, its entity is "cold", the attribute is "feature", and the relationship is "relationship between medicine and disease". In this embodiment, the question type is one of the most critical elements of the question vector, and the prediction accuracy of the question type is directly related to the prediction accuracy of the query statement, and thus to the accuracy of the question answer prediction.
Further, an entity set refers to a set of all entities involved in a natural language problem, a relationship set refers to a set of all relationships involved in a natural language problem, and an attribute set refers to a set of all attributes involved in a natural language problem. It should be noted that, in a natural language question, at least one entity is included, and at least one attribute is also included or at least one relationship is included, that is, the attribute and the relationship do not necessarily appear in the same natural language question at the same time, but the natural language question at least includes at least one attribute or at least one relationship, otherwise, the query statement cannot be constructed. In this embodiment, the entity, the relationship and the attribute may be extracted from the problem vector, or may be obtained by performing semantic analysis on the problem vector, for example, the natural language problem "cold" has only one word, so that the entity may be extracted as "cold", and in this natural language, other entities are not involved and therefore do not belong to the relationship query problem, and at this time, by context analysis, an attribute "definition" or "feature" may be predicted for this natural language problem, so as to supplement the intention of the user to input the natural language problem.
In this embodiment, after the natural language problem is converted into the problem vector, the problem type, entity, relationship and attribute of the problem vector may be predicted by a multitask classification function trained in advance in the target language model, then an entity set may be constructed according to the predicted entity, a relationship set may be constructed according to the predicted relationship, and an attribute set may be constructed according to the predicted attribute. In this embodiment, the problem type, the entity set, the relationship set, and the attribute set of the problem vector are collectively referred to as element information of the problem vector, where the problem type, the certain entity, the certain relationship, or the certain attribute may be referred to as one element of the problem vector. According to the method and the device, the element information of the problem vector is classified and predicted through the multitask classification function trained in advance in the target language model, and the construction accuracy of the query statement can be improved.
103. The target language model is used as a decoder to convert the problem vector into a query statement of the graph database based on the element information of the problem vector.
Specifically, based on the element information predicted by the target language model, the sentence pattern grammar of the query sentence of the graph database can be determined, the query sentence of the graph database corresponding to the problem vector can be predicted by using the decoder of the target language model through the sentence pattern grammar of the query sentence of the graph database and the predicted elements, and then the related information can be searched in the knowledge graph through the query sentence of the graph database.
For example, if the question type of the question vector is an attribute query type, then the Entity and attribute corresponding to the attribute query type need to be extracted from the question vector, and then a graph database query sentence is generated based on the sentence pattern grammar corresponding to the attribute query type and the respective Entity elements and attribute elements, for example, the natural language question "what causes the vaccinia on face" corresponds to the generated graph database query sentence being "MATCH (e: entity { name:" vaccinia on face "}) RETURN e.reflection". Accordingly, if the question type of the question vector is a relation query type, it is necessary to extract an Entity and a relation corresponding to the relation query type from the question vector, and then generate a graph database query sentence based on a sentence pattern grammar corresponding to the relation query type and each Entity element and relation element, for example, "what the specific medicine of the natural language question" cold "corresponds to and generates, which is" MATCH (e 1: entity { name: "cold" }) - [: can_cure ] - > (e 2: entity) RETURN e2.Name ".
104. And executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder.
Specifically, after generating the graph database query statement, the graph database query statement may be executed in a pre-established knowledge graph to obtain a query result, and then the question vector and the query result may be input into a decoder of the target language model to generate a natural language answer corresponding to the query result through the decoder. For example, by executing a map database query sentence "MATCH (e: activity { name:" vaccinia on face "}) in a knowledge graph in the medical field, a query result of" e.reflection= "may be caused by endocrine disorders, skin grease hypersecretion, poor eating habits, etc., and further, by converting the query result by a target language model, a natural language answer may be obtained as" cause of vaccinia on face may be caused by endocrine disorders, skin grease hypersecretion, poor eating habits, etc. By the method, accuracy, smoothness, consistency and logic of the problem response can be effectively improved.
In this embodiment, if the same question vector includes multiple question types or includes multiple same question types, a graph database query statement may be constructed according to each question type, then, based on each graph database query statement, the graph database query statement may be executed in a pre-established knowledge graph to obtain a query result corresponding to each graph database query statement, further, all the query results may be spliced to obtain a query result to be converted, and finally, the question vector and the spliced query result may be input to a decoder of the target language model to generate a natural language answer corresponding to the query result through the decoder.
According to the knowledge graph-based problem response method provided by the embodiment, firstly, a pre-trained target language model is used as an encoder to convert natural language problems input by a user into problem vectors, then the problem vectors are classified and analyzed by the target language model to obtain various element information such as problem types, entity sets, relation sets and attribute sets of the problem vectors, further, the target language model is used as a decoder to convert the problem vectors into graph database query sentences based on the element information of the problem vectors, finally, the graph database query sentences are executed in the pre-established knowledge graph to obtain query results, and the target language model is used as the decoder to convert the query results into natural language answers. The method utilizes the language model to obtain query sentences and answers to questions for natural language understanding and generating capacity, can effectively cover the possible occurrence of natural language in various contexts, and effectively avoids misjudgment or missed judgment of the questions. In addition, the language model is used for classifying and analyzing the natural language questions, generating query sentences and generating natural language answers, so that the accuracy of query sentence conversion can be effectively improved, the generated graph database query sentences and the natural language questions have higher matching degree, and the generated natural language answers are more accurate, smooth, consistent and logical.
Further, as a refinement and extension of the specific implementation manner of the foregoing embodiment, in order to fully describe the implementation process of the present embodiment, a method for responding to a problem based on a knowledge graph is provided, as shown in fig. 2, and the method includes the following steps:
201. and acquiring a triplet data set in the target professional field, and constructing a knowledge graph based on the triplet data set.
Specifically, before predicting answers to questions, a knowledge graph of the target professional field may be first constructed, specifically, the method may be implemented by the following steps: firstly, a triplet data set of a target professional field is obtained, wherein each triplet data set in the triplet data set comprises a problem, a query statement and an answer, then, based on the triplet data set, a plurality of entities, at least one attribute of each entity, a relation between every two entities and a type of each relation are extracted, finally, each entity can be taken as a node, each attribute of each entity can be taken as a child node of the node, the relation between every two entities can be taken as an edge, and the type of each relation can be taken as a weight of the edge, so that a knowledge graph of the target professional field is constructed.
Taking the medical field as an example, when the knowledge graph of the medical field is constructed, various types of entities such as diseases, symptoms, medicines, examinations, treatments, departments, doctors and the like can be collected as nodes of the knowledge graph, and various types of relationships such as relationships between diseases and symptoms, relationships between medicines and diseases, relationships between examinations and diseases, relationships between treatments and diseases, relationships between doctors and departments, relationships between doctors and hospitals, relationships between hospitals and regions, relationships between medicines, relationships between examinations and treatments and the like and prices, relationships between medicines and side effects, relationships between treatments and duration and the like are taken as the weights of edges between every two nodes. Meanwhile, tens of thousands, even hundreds of thousands or millions of natural language questions related to medical treatment, and query sentences and answers corresponding to each natural language question can be collected through the published websites, forums and other approaches to be used as a data set of knowledge graph questions and answers.
202. And optimizing the pre-trained language model based on the triplet data set corresponding to the knowledge graph to obtain the target language model.
Specifically, before multi-classification task prediction, query sentence generation and question answer generation are performed by using the target language model, parameter optimization can be performed on the general language model based on a data set corresponding to the knowledge graph, so as to obtain the target language model applicable to knowledge questions and answers in the target professional field. According to the method, the target language model is obtained by carrying out parameter adjustment on the language model, so that the model is more suitable for knowledge question-answering tasks in the professional field, and compared with a general language model, the knowledge-graph-based target language model can effectively improve generalization capability and robustness of the model, so that accuracy of multi-task classification prediction, query statement generation and answer generation is improved.
In this embodiment, the method for obtaining the target language model by performing parameter optimization on the general language model may be implemented by the following steps: firstly, acquiring a triplet data set corresponding to a knowledge graph, wherein each triplet data in the triplet data set comprises a question, a query statement and an answer, then searching a target parameter with the maximum target probability value in a pre-trained language model aiming at each triplet data, wherein the target probability value is the sum of a first probability value of the query statement through the question and a second probability value of the answer predicted by the question and the query statement, and finally, iteratively updating the numerical value of the target parameter by using a gradient descent method to continuously increase the target probability value, and optimizing the pre-trained language model by using the updated target parameter when the target probability value reaches a preset probability threshold value to obtain the target language model.
For example, the parameter optimization method of the target language model based on the knowledge graph may be represented by the following formula (one), where θ is a parameter of the pre-trained language model, and the fine-tuning of the parameter of the target language model may be represented as:
θ * =argmax θ(Q,S,A)∈D log P (S|Q; θ) +log P (A|Q, S; θ) (equation one)
Wherein D is a question-query statement-answer triplet data set in the knowledge graph, Q is a question, S is a query statement, A is an answer, θ is a parameter of a pre-trained language model, θ * Is a parameter of the updated language model. The meaning of this formula is that given a question-query-answer triplet dataset D in a knowledge graph, the parameters θ of an optimal language model can be found such that the sum of probabilities of query and answers generated on dataset D is maximized. This sum of probabilities is the sum of the probability of generating a query statement and the probability of generating an answer. Then, θ can be optimized using a gradient descent method, i.e., the value of θ is continuously updated so that the probability sum increases. When the probability sum increases to a preset probability threshold, the current parameter theta can be utilized * Optimizing the language model to obtain a target language model, so that the target language model can be utilized to classify, analyze and generate query sentences and answers to the new questions.
In this embodiment, only one target language model needs to be trained, and the target language model includes one encoder and one decoder. The encoder is used for encoding the natural language questions and predicting element information such as the types, the entities, the relations, the attributes and the like of the questions, and the decoder is used for generating query sentences and natural language answers according to the encoded question vectors and query results.
203. And receiving the natural language questions input by the user, and converting the natural language questions into question vectors by using the pre-trained target language model as an encoder.
Specifically, the natural language question may be encoded into a vector representation using the trained target language model as an encoder, i.e., the natural language question is converted into a question vector using the encoder of the target language model. By converting the natural language questions into question vectors, the following operations of multitasking classification, query statement prediction, answer prediction and the like can be conveniently carried out on the natural language questions.
204. And classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector.
Specifically, multiple factors such as the type, entity, relationship, attribute, etc. of the problem can be predicted simultaneously by using a multitask learning manner. The trained target language model may include a plurality of classification functions, such as a question type classification function, an entity classification function, a relationship classification function, and an attribute classification function, where each function may be used to predict an element of a question vector. Specifically, classifying and predicting the problem vector by using a problem type classification function to obtain at least one problem type of the problem vector; classifying and predicting the problem vector by utilizing an entity classification function to obtain at least one entity of the problem vector, and constructing an entity set according to the at least one entity; classifying and predicting the problem vector by utilizing a relationship classification function to obtain at least one relationship of the problem vector, and constructing a relationship set according to the at least one relationship; and classifying and predicting the problem vector by utilizing the attribute classification function to obtain at least one attribute of the problem vector, and constructing an attribute set according to the at least one attribute.
For example, let Q be a natural language question, T be a question type, E be an entity set, R be a relationship set, and a be an attribute set. The problem classification and resolution can be expressed in terms of equation two.
P(T,E,R,A|Q)=P(T|Q)∏ e∈E P(e|Q)∏ r∈R P(r|Q)∏ a∈A P (a|Q) (equation II)
The meaning of the formula II is that a natural language question Q is given, and meanwhile, the type T of the question is predicted, and the probabilities of an entity set E, a relation set R and an attribute set A which are involved in the question are calculated. The probability is equal to the probability of predicting the problem type, multiplied by the probability of predicting each entity, multiplied by the probability of predicting each relation, multiplied by the probability of predicting each attribute, and finally, the problem type, entity set, relation set and attribute set corresponding to the maximum value of the probability can be taken as the predicted element information. In this example, it is assumed that the question types, entities, relationships, and attributes are independent of each other and are not affected by each other.
Further, using the target language model as an Encoder, the natural language question Q may be encoded into a question vector Q in the form of a formula three, where "enc" in the lower right corner of the formula is an abbreviation of Encoder, meaning encoded.
q=chatglm enc (Q) (equation three)
Further, by using the manner of multitasking, the problem type T, the entity set E, the relation set R, and the attribute set a can be predicted by the formula (four):
P(T|Q)=softmax(W T q+b T )
P(e|Q)=sigmoid(W e q+b e )
P(r|Q)=sigmoid(W r q+b r )
P(a|Q)=sigmoid(W a q+b a ) (equation IV)
Wherein W is T ,W e ,W r ,W a And b T ,b e ,b r ,b a Is a learnable parameter. Equation four specifically describes how the probabilities of the problem types, entities, relationships, and attributes are predicted. They are all based on the problem vector q-passing of the target language model after coding The same linear transformation and activation function. The softmax function is a commonly used classification function that converts a vector into a probability distribution that represents the likelihood of each class. The sigmoid function is a commonly used binary function that can convert a numerical value to a value between 0 and 1, indicating the likelihood that an event will or will not occur. The fourth formula and the second formula are complementary relations, which describe the problem classification and analysis processes, and each factor in the second formula can be calculated by using the fourth formula, so that the prediction result of the element information is obtained.
205. The target language model is used as a decoder to convert the problem vector into a query statement of the graph database based on the element information of the problem vector.
Specifically, the trained target language model is used as a decoder, and the encoded problem vector is used as input to generate a graph database query statement corresponding to the problem vector. The specific process comprises the following steps: firstly, determining the sentence grammar of a query sentence of a graph database based on element information of a problem vector, then, according to the sentence grammar, using a target language model as a decoder, inputting the problem vector into the decoder to predict each query word in the query sentence of the graph database one by one, and finally, splicing each query word in the query sentence of the graph database to obtain the query sentence of the graph database.
In this embodiment, based on the element information of the problem vector, the manner of determining the sentence pattern grammar of the query sentence of the graph database may be implemented by the following steps: firstly, acquiring a problem type of a problem vector, wherein the problem type can comprise an attribute query type and/or a relation query type, if the problem type comprises the attribute query type, acquiring an entity corresponding to the attribute query type from an entity set, and acquiring an attribute corresponding to the attribute query type from the attribute set; and if the problem type comprises a relation query type, acquiring an entity corresponding to the relation query type from the entity set, acquiring a relation corresponding to the relation query type from the relation set, and finally determining the sentence grammar of the query sentence of the graph database based on the entity and the attribute corresponding to the attribute query type and/or the entity and the relation corresponding to the relation query type.
For example, let S be the graph database query statement, the graph database query statement can be represented by the following formula five.
Wherein the problem vectors q and s can be processed using the target language model as a decoder <t S is generated as input by equation six t Wherein the abbreviation "dec" Decoder is the meaning of Decoder.
s t =chatglm dec (q,s <t ) (equation six)
Wherein t in the formula five and the formula six represents the t-th word, S, of the query statement S t T-th word, S representing query statement S <t Representing the first t-1 words of query statement S. For example, if query statement S is MATCH (e: entity { name: "Zhang Sanj") RETURN e.age, then S 1 Is MATCH, s 2 Is (, s) 3 Is MATCH (the meaning of formulas five and six is that given a natural language question Q, a probability of generating a corresponding graph database query statement S is equal to the product of the probabilities of generating each query word, where the probability of generating each query word depends on the question Q and the words that have been generated previously.
206. And executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder.
Specifically, the query statement of the graph database is executed in the knowledge graph, so that a query result can be obtained. The query result can be converted into a natural language answer using the trained target language model as a decoder. The specific process of converting natural language answers is as follows: and using the target language model as a decoder, inputting the question vector and the query result into the decoder to predict each word in the natural language answer one by one, and then splicing each word in the natural language answer to obtain the natural language answer.
For example, using the target language model as a decoder, the query result as an input, the generation of a natural language answer can be represented by the following formula seven. Wherein, let A be natural language answer, R be query result, then answer generation can be expressed as:
wherein, using the target language model as a decoder, the problem vector q and the query result R are used as inputs, and a can be generated by a formula eight t
a t =chatglm dec (q,R,a <t ) (equation eight)
Wherein A represents a natural language answer, a t The t th word, a, representing the natural language answer A <t The first t-1 words representing the natural language answer a. For example, if the natural language answer A is Zhang three, age 40, then a 1 Is Zhang san, a 2 For, a <3 Is Zhang three. A|q in equation seven represents the probability that a given question Q generates an answer a, unlike a|q in equation two, which represents the set of attributes involved in a natural language question. The meaning of the formula seven and the formula eight is that given a natural language question Q and a corresponding query result R, a probability of a corresponding natural language answer a is generated. This probability is equal to the product of the probabilities of generating each word. Wherein the probability of generating each term depends on the question Q, the query result R and the previously generated terms.
207. And sending the natural language answer to the client where the user is located.
Specifically, after the natural language answer is generated, the natural language answer can be sent to the client where the user is located, so that the client can display or play the generated natural language answer in various modes such as characters, pictures, sounds and the like. By the method, timeliness of obtaining the answers to the questions by the user can be improved, and therefore experience of the user is improved.
According to the knowledge graph-based problem response method, the pre-trained language model is optimized and adjusted by utilizing the information such as the entity, the relation and the attribute in the knowledge graph, so that the optimized model is more suitable for the knowledge question-answering task in the professional field, and compared with the general language model, the knowledge graph-based fine-tuning target language model can effectively improve the generalization capability and the robustness of the model, so that the accuracy of model prediction is improved. In addition, the semantic information and the context information in the problems can be captured better compared with the existing rules or statistical models through factors such as the types, the entities, the relations and the attributes of the problems predicted by the target language model, so that the accuracy of problem classification and analysis is improved. And the target language model is used as a decoder, the coded problem vector is used as input, a corresponding graph database query sentence is generated, compared with the existing template or grammar analysis method, the target language model can better generate the query sentence, meanwhile, the target language model is used as the decoder, the query result is used as input, a natural language shape answer is generated, compared with the existing rule or template method, the target language model can better generate smooth, coherent and logical answers, and therefore user satisfaction is improved. Based on the method, the requirements of users on various natural language questions in the professional field can be met, natural language answers meeting the user intention are returned, and the satisfaction degree and the trust degree of the users are improved.
Further, as a specific implementation of the methods shown in fig. 1 and fig. 2, the present embodiment provides a problem response device based on a knowledge graph, as shown in fig. 3, where the device includes: a problem vector conversion module 31, a problem classification analysis module 32, a query statement generation module 33, and a query result conversion module 34.
The question vector conversion module 31 is configured to receive a natural language question input by a user, and convert the natural language question into a question vector by using a pre-trained target language model as an encoder;
the problem classification analysis module 32 is configured to classify and analyze the problem vector by using the target language model, so as to obtain multiple element information in a problem type, an entity set, a relationship set and an attribute set of the problem vector;
a query term generation module 33, configured to convert the problem vector into a graph database query term based on element information of the problem vector using the target language model as a decoder;
the query result conversion module 34 may be configured to execute the graph database query sentence in a pre-established knowledge graph to obtain a query result, and convert the query result into a natural language answer by using the target language model as a decoder.
In a specific application scenario, the target language model comprises a problem type classification function, an entity classification function, a relationship classification function and an attribute classification function; the problem classification analysis module 32 is specifically configured to perform classification prediction on the problem vector by using the problem type classification function to obtain at least one problem type of the problem vector; classifying and predicting the problem vector by utilizing the entity classification function to obtain at least one entity of the problem vector, and constructing the entity set according to the at least one entity; classifying and predicting the problem vector by utilizing the relationship classification function to obtain at least one relationship of the problem vector, and constructing the relationship set according to the at least one relationship; and/or classifying and predicting the problem vector by utilizing the attribute classification function to obtain at least one attribute of the problem vector, and constructing the attribute set according to the at least one attribute.
In a specific application scenario, the query sentence generation module 33 is specifically configured to determine a sentence pattern grammar of the query sentence of the graph database based on the element information of the problem vector; according to the sentence grammar, using the target language model as a decoder, inputting the problem vector into the decoder, and predicting each query word in the query sentence of the graph database one by one; and splicing each query word in the query sentence of the graph database to obtain the query sentence of the graph database.
In a specific application scenario, the query statement generating module 33 is specifically configured to obtain a question type of the question vector, where the question type includes an attribute query type and/or a relationship query type; if the problem type comprises the attribute query type, acquiring an entity corresponding to the attribute query type from the entity set, and acquiring an attribute corresponding to the attribute query type from the attribute set; if the problem type comprises the relation query type, acquiring an entity corresponding to the relation query type from the entity set, and acquiring a relation corresponding to the relation query type from the relation set; determining the sentence grammar of the query sentence of the graph database based on the entity and the attribute corresponding to the attribute query type and/or the entity and the relationship corresponding to the relationship query type.
In a specific application scenario, the query result conversion module 34 may be specifically configured to utilize the target language model as a decoder, input the question vector and the query result into the decoder, and predict each term in the natural language answer one by one; and splicing each word in the natural language answers to obtain the natural language answers.
In a specific application scenario, as shown in fig. 4, the apparatus further includes a knowledge graph construction module 35, where the knowledge graph construction module 35 is specifically configured to obtain a triplet data set in the target professional field, where each triplet data in the triplet data set includes a question, a query statement, and an answer; extracting a plurality of entities, a plurality of attributes of each of the entities, a relationship between each two of the entities, and a type of each of the relationships based on the triplet data set; and constructing the knowledge graph by taking each entity as a node, taking each attribute of each entity as a child node of the node, taking the relation between every two entities as an edge, and taking the type of each relation as the weight of the edge.
In a specific application scenario, as shown in fig. 4, the apparatus further includes a language model optimization module 36, where the language model optimization module 36 is specifically configured to obtain a triplet data set corresponding to the knowledge graph, where each triplet data in the triplet data set includes a question, a query statement, and an answer; searching target parameters which enable target probability values to be maximum in a pre-trained language model according to each triplet data, wherein the target probability values are the sum of a first probability value of predicting the query statement through the problem and a second probability value of predicting the answer through the problem and the query statement; and iteratively updating the numerical value of the target parameter by using a gradient descent method so that the target probability value is continuously increased, and optimizing the pre-trained language model by using the updated target parameter when the target probability value reaches a preset probability threshold value to obtain the target language model.
It should be noted that, in the other corresponding descriptions of each functional unit related to the problem response device based on the knowledge graph provided in this embodiment, reference may be made to corresponding descriptions in fig. 1 and fig. 2, and no further description is given here.
Based on the above methods shown in fig. 1 and fig. 2, correspondingly, the present embodiment further provides a storage medium, on which a computer program is stored, which when executed by a processor, implements the above method for answering a problem based on a knowledge graph shown in fig. 1 and fig. 2.
Based on such understanding, the technical solution of the present application may be embodied in the form of a software product, where the software product to be identified may be stored in a non-volatile storage medium (may be a CD-ROM, a U-disc, a mobile hard disk, etc.), and include several instructions for causing a computer device (may be a personal computer, a server, or a network device, etc.) to execute the method described in the various implementation scenarios of the present application.
Based on the method shown in fig. 1 and fig. 2 and the embodiment of the problem response device based on the knowledge graph shown in fig. 3 and fig. 4, in order to achieve the above object, the present embodiment further provides a computer device for problem response based on the knowledge graph, which may specifically be a personal computer, a server, a smart phone, a tablet computer, a smart watch, or other network devices, etc., where the computer device includes a storage medium and a processor; a storage medium storing a computer program and an operating system; a processor for executing a computer program to implement the method as shown in fig. 1 and 2.
Optionally, the computer device may further include an internal memory, a communication interface, a network interface, a camera, a Radio Frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, a Display screen (Display), an input device such as a Keyboard (Keyboard), and the like, and optionally, the communication interface may further include a USB interface, a card reader interface, and the like. The network interface may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface), etc.
It will be appreciated by those skilled in the art that the computer device structure provided by the present embodiment for identification of an operational action is not limiting of the computer device and may include more or fewer components, or may combine certain components, or a different arrangement of components.
The storage medium may also include an operating system, a network communication module. The operating system is a program for managing the hardware of the computer device and the software resources to be identified, and supports the operation of the information processing program and other software and/or programs to be identified. The network communication module is used for realizing communication among all components in the storage medium and communication with other hardware and software in the information processing computer equipment.
From the above description of the embodiments, it will be apparent to those skilled in the art that the present application may be implemented by means of software plus necessary general hardware platforms, or may be implemented by hardware. According to the technical scheme, a pre-trained target language model is used as an encoder to convert natural language questions input by a user into question vectors, then the question vectors are classified and analyzed by the target language model to obtain various element information such as question types, entity sets, relation sets and attribute sets of the question vectors, the target language model is used as a decoder to convert the question vectors into graph database query sentences based on the element information of the question vectors, finally the graph database query sentences are executed in a pre-established knowledge graph to obtain query results, and the target language model is used as the decoder to convert the query results into natural language answers. Compared with the prior art, the method can effectively cover the possible situations of natural language in various contexts, thereby avoiding erroneous judgment or missed judgment of the problem. In addition, the matching degree of the query statement of the graph database generated by the method and the natural language question is higher, and the generated natural language answer is smoother, coherent and logical.
Those skilled in the art will appreciate that the drawing is merely a schematic illustration of a preferred implementation scenario and that the modules or flows in the drawing are not necessarily required to practice the application. Those skilled in the art will appreciate that modules in an apparatus in an implementation scenario may be distributed in an apparatus in an implementation scenario according to an implementation scenario description, or that corresponding changes may be located in one or more apparatuses different from the implementation scenario. The modules of the implementation scenario may be combined into one module, or may be further split into a plurality of sub-modules.
The above-mentioned inventive sequence numbers are merely for description and do not represent advantages or disadvantages of the implementation scenario. The foregoing disclosure is merely illustrative of some embodiments of the application, and the application is not limited thereto, as modifications may be made by those skilled in the art without departing from the scope of the application.

Claims (10)

1. A knowledge-graph-based problem response method, the method comprising:
receiving a natural language question input by a user, and converting the natural language question into a question vector by using a pre-trained target language model as an encoder;
classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector;
Converting the problem vector into a graph database query statement based on element information of the problem vector by using the target language model as a decoder;
executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder.
2. The method of claim 1, wherein the target language model comprises a question type classification function, an entity classification function, a relationship classification function, and an attribute classification function; classifying and analyzing the problem vector by using the target language model to obtain a plurality of element information in the problem type, the entity set, the relation set and the attribute set of the problem vector, wherein the element information comprises:
classifying and predicting the problem vector by utilizing the problem type classification function to obtain at least one problem type of the problem vector;
classifying and predicting the problem vector by utilizing the entity classification function to obtain at least one entity of the problem vector, and constructing the entity set according to the at least one entity;
Classifying and predicting the problem vector by utilizing the relationship classification function to obtain at least one relationship of the problem vector, and constructing the relationship set according to the at least one relationship; and/or
And carrying out classification prediction on the problem vector by utilizing the attribute classification function to obtain at least one attribute of the problem vector, and constructing the attribute set according to the at least one attribute.
3. The method of claim 1, wherein the converting the problem vector into a graph database query statement based on element information of the problem vector using the target language model as a decoder, comprises:
determining sentence pattern grammar of the query sentence of the graph database based on the element information of the problem vector;
according to the sentence grammar, using the target language model as a decoder, inputting the problem vector into the decoder, and predicting each query word in the query sentence of the graph database one by one;
and splicing each query word in the query sentence of the graph database to obtain the query sentence of the graph database.
4. The method of claim 3, wherein the determining a sentence grammar of the graph database query sentence based on element information of the problem vector comprises:
Obtaining a problem type of the problem vector, wherein the problem type comprises an attribute query type and/or a relationship query type;
if the problem type comprises the attribute query type, acquiring an entity corresponding to the attribute query type from the entity set, and acquiring an attribute corresponding to the attribute query type from the attribute set;
if the problem type comprises the relation query type, acquiring an entity corresponding to the relation query type from the entity set, and acquiring a relation corresponding to the relation query type from the relation set;
determining the sentence grammar of the query sentence of the graph database based on the entity and the attribute corresponding to the attribute query type and/or the entity and the relationship corresponding to the relationship query type.
5. The method of claim 1, wherein said converting said query result to a natural language answer using said target language model as a decoder comprises;
inputting the question vector and the query result into a decoder by using the target language model as the decoder, and predicting each word in the natural language answer one by one;
And splicing each word in the natural language answers to obtain the natural language answers.
6. The method according to any one of claims 1 to 5, wherein the knowledge-graph construction method comprises:
acquiring a triplet data set in the target professional field, wherein each triplet data in the triplet data set comprises a question, a query statement and an answer;
extracting a plurality of entities, at least one attribute of each of the entities, a relationship between each two of the entities, and a type of each of the relationships based on the triplet data set;
and constructing the knowledge graph by taking each entity as a node, taking each attribute of each entity as a child node of the node, taking the relation between every two entities as an edge, and taking the type of each relation as the weight of the edge.
7. The method according to any one of claims 1 to 5, wherein the training method of the target language model comprises:
acquiring a triplet data set corresponding to the knowledge graph, wherein each triplet data in the triplet data set comprises a question, a query statement and an answer;
Searching target parameters which enable target probability values to be maximum in a pre-trained language model according to each triplet data, wherein the target probability values are the sum of a first probability value of predicting the query statement through the problem and a second probability value of predicting the answer through the problem and the query statement;
and iteratively updating the numerical value of the target parameter by using a gradient descent method so that the target probability value is continuously increased, and optimizing the pre-trained language model by using the updated target parameter when the target probability value reaches a preset probability threshold value to obtain the target language model.
8. A knowledge-graph-based problem response apparatus, the apparatus comprising:
the problem vector conversion module is used for receiving a natural language problem input by a user, and converting the natural language problem into a problem vector by using a pre-trained target language model as an encoder;
the problem classification analysis module is used for classifying and analyzing the problem vector by utilizing the target language model to obtain various element information in the problem type, the entity set, the relation set and the attribute set of the problem vector;
The query statement generation module is used for converting the problem vector into a graph database query statement based on element information of the problem vector by using the target language model as a decoder;
and the query result conversion module is used for executing the query statement of the graph database in the pre-established knowledge graph to obtain a query result, and converting the query result into a natural language answer by using the target language model as a decoder.
9. A storage medium having stored thereon a computer program, which when executed by a processor, implements the steps of the method of any of claims 1 to 7.
10. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the computer program when executed by the processor implements the steps of the method according to any one of claims 1 to 7.
CN202310795311.0A 2023-06-30 2023-06-30 Knowledge graph-based problem response method, device, medium and computer equipment Pending CN116821301A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310795311.0A CN116821301A (en) 2023-06-30 2023-06-30 Knowledge graph-based problem response method, device, medium and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310795311.0A CN116821301A (en) 2023-06-30 2023-06-30 Knowledge graph-based problem response method, device, medium and computer equipment

Publications (1)

Publication Number Publication Date
CN116821301A true CN116821301A (en) 2023-09-29

Family

ID=88118161

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310795311.0A Pending CN116821301A (en) 2023-06-30 2023-06-30 Knowledge graph-based problem response method, device, medium and computer equipment

Country Status (1)

Country Link
CN (1) CN116821301A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117271754A (en) * 2023-11-17 2023-12-22 杭州海康威视数字技术股份有限公司 Data retrieval method, device and equipment
CN117609470A (en) * 2023-12-08 2024-02-27 中科南京信息高铁研究院 Question-answering system based on large language model and knowledge graph, construction method thereof and intelligent data management platform
CN117972077A (en) * 2024-03-28 2024-05-03 浪潮通信信息系统有限公司 Query result generation method and device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117271754A (en) * 2023-11-17 2023-12-22 杭州海康威视数字技术股份有限公司 Data retrieval method, device and equipment
CN117271754B (en) * 2023-11-17 2024-06-04 杭州海康威视数字技术股份有限公司 Data retrieval method, device and equipment
CN117609470A (en) * 2023-12-08 2024-02-27 中科南京信息高铁研究院 Question-answering system based on large language model and knowledge graph, construction method thereof and intelligent data management platform
CN117972077A (en) * 2024-03-28 2024-05-03 浪潮通信信息系统有限公司 Query result generation method and device

Similar Documents

Publication Publication Date Title
CN110837550B (en) Knowledge graph-based question answering method and device, electronic equipment and storage medium
CN110334201B (en) Intention identification method, device and system
EP4060565A1 (en) Method and apparatus for acquiring pre-trained model
CN112164391B (en) Statement processing method, device, electronic equipment and storage medium
US7389208B1 (en) System and method for dynamic knowledge construction
CN116821301A (en) Knowledge graph-based problem response method, device, medium and computer equipment
US11238132B2 (en) Method and system for using existing models in connection with new model development
CN112287089B (en) Classification model training and automatic question-answering method and device for automatic question-answering system
CN113157863A (en) Question and answer data processing method and device, computer equipment and storage medium
CN113704460B (en) Text classification method and device, electronic equipment and storage medium
WO2020073533A1 (en) Automatic question answering method and device
CN113268609A (en) Dialog content recommendation method, device, equipment and medium based on knowledge graph
CN116611546A (en) Knowledge-graph-based landslide prediction method and system for target research area
CN117932022A (en) Intelligent question-answering method and device, electronic equipment and storage medium
CN112199958A (en) Concept word sequence generation method and device, computer equipment and storage medium
CN117290478A (en) Knowledge graph question-answering method, device, equipment and storage medium
US20240037335A1 (en) Methods, systems, and media for bi-modal generation of natural languages and neural architectures
CN115146589B (en) Text processing method, device, medium and electronic equipment
CN110633363B (en) Text entity recommendation method based on NLP and fuzzy multi-criterion decision
CN118093885B (en) Data processing method, device and equipment, medium and product
CN113342934B (en) Word vector determining method and device, storage medium and electronic device
CN117009532B (en) Semantic type recognition method and device, computer readable medium and electronic equipment
CN116755683B (en) Data processing method and related device
CN114492661B (en) Text data classification method and device, computer equipment and storage medium
US11829735B2 (en) Artificial intelligence (AI) framework to identify object-relational mapping issues in real-time

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination