Method and device for processing question and answer tasks in combination with knowledge graph
By building a knowledge graph and customized entity extraction model, and using knowledge graph retrieval to provide prompt information, it solves the shortcomings of large language models in question positioning and knowledge retrieval in question and answer tasks, achieving more efficient question and answer processing performance and lower improvement costs.
Patent Information
- Application Number
- CN202411477728.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-10-22
AI Technical Summary
When handling question-and-answer tasks, existing large language models have problems such as unclear problem positioning, inaccurate knowledge retrieval, and incorrect answers. Conventional improvement methods require a lot of computing resources and manual construction of complex training corpus, resulting in high improvement costs. Long cycle.
Based on the pre -constructing knowledge map, and using the characteristics of a large language model, the component is based on the customized entity extraction model, and the knowledge map is used to obtain the knowledge information related to the correct answer as a prompt information input large language model for answering text generation.
The error rate of the Q & A task is reduced, the processing performance of the question and answer task is improved, the improvement cycle is shortened, the improvement efficiency is improved, and the cost is reduced.
Smart Images

Figure CN119357405A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method and device for processing question-answering tasks in combination with a knowledge graph. Background Art
[0002] Large Language Models (LLMs) can correctly understand and generate natural language texts through learning massive text corpora in the pre-training stage and customized text corpora in the fine-tuning stage. Large language models that have completed pre-training and fine-tuning perform well in natural language processing (NLP) tasks such as text generation and machine translation. However, in practical applications, we found that if such large language models are directly used to process question answering (QA) tasks, the processing results are not very ideal. The main reason is that the large language models are not trained in information extraction and knowledge retrieval in the pre-training and fine-tuning stages, which makes it easy for the model to have unclear problem location, inaccurate knowledge retrieval, and wrong answer content when processing question answering tasks.
[0003] To improve this situation, the conventional method is to re-train the large language model in terms of information extraction and knowledge retrieval in order to improve the accuracy of question and answering. However, this conventional method requires the manual construction of a complex training corpus on the one hand, and on the other hand, it also requires a lot of computing resources to train the model on a large scale. The resulting training cycle will be longer and the training cost will be higher. In other words, according to the current conventional improvement methods, the corresponding question and answer task improvement cost is not affordable for every model development / application organization. Therefore, shortening the improvement cycle and reducing the improvement cost while improving the processing performance of question and answer tasks has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The purpose of the present invention is to provide a method, device, electronic device and computer-readable storage medium for processing question-answering tasks in combination with knowledge graphs in view of the defects of the prior art. The present invention constructs a knowledge graph in advance through big data collection, and customizes an entity extraction model based on the feature extraction component of a large language model, and the large language model automatically generates and processes the model training data set of the entity extraction model according to the knowledge graph, and trains the entity extraction model based on the generated data set; and in each question-answering task processing process after the model training is completed, the entity extraction model first extracts entity triples from the question text, and then searches the knowledge graph according to the entity triples extracted at that time to obtain the corresponding knowledge text, and then inputs the knowledge text obtained at that time as reference / prompt information together with the question text into the large language model for corresponding answer text generation processing. When processing question-answering tasks, the present invention first obtains knowledge information related to the correct answer through knowledge graph retrieval, and then uses the obtained knowledge information to prompt the large language model to generate the corresponding answer text. The present invention can reduce the error rate of the question-answering task and achieve the purpose of improving the processing performance of the question-answering task; the present invention does not perform large-scale training on the large language model, but only performs local training on the customized small model. It does not construct a training data set through manual data collection, but only uses the text generation capability of the large model to automatically construct the training data set. The present invention can shorten the improvement cycle, improve the improvement efficiency, and reduce the improvement cost.
[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present invention provides a method for processing a question-answering task in combination with a knowledge graph, the method comprising:
[0006] Constructing the first knowledge graph in advance through big data collection;
[0007] A type of large language model that has been pre-trained and fine-tuned is used as the corresponding first large language model; a processing model for entity triple extraction is customized based on the feature extraction component of the first large language model and recorded as the corresponding entity extraction model; the first large language model automatically generates a model training data set of the entity extraction model according to the first knowledge graph to obtain a corresponding first data set; and the entity extraction model is trained based on the first data set;
[0008] After the model training is completed, the question text received from the user is recorded as the corresponding current question text; the entity extraction model performs entity triple extraction processing on the current question text to obtain the corresponding current entity triplet; and performs knowledge retrieval processing based on the current entity triplet and the first knowledge graph to obtain the corresponding current knowledge text; and the current question text and the current knowledge text are brought into the preset question and answer instruction template to perform question and answer instruction text splicing processing to obtain the corresponding current question and answer instruction text; and the current question and answer instruction text is input into the first language model to perform answer text generation processing to obtain the corresponding current answer text to be fed back to the user.
[0009] Preferably, the first knowledge graph consists of a first node set and a first edge set; the first node set includes a plurality of first nodes; the first edge set includes a plurality of first edges;
[0010] Each of the first nodes corresponds to an entity; the node attributes of the first node include a node identifier, a node update time, a node entity concept type, a node entity role, and a node entity attribute set; the node identifier is a unique identifier of the current node; the node update time is the latest addition or update time of the current node; the node entity concept type is a class of preset entity concept types; the node entity role is a specific role parameter of the entity corresponding to the current node;
[0011] Each of the first edges is a directed edge; the starting node of each of the first edges is recorded as a parent entity node, and the ending node is recorded as a child entity node; the edge attributes of the first edge include edge identifier, edge update time, parent entity node identifier, child entity node identifier, and parent-child entity relationship type; the edge identifier is a unique identifier of the current edge; the edge update time is the latest addition or update time of the current edge; the parent entity node identifier is the node identifier of the parent entity node corresponding to the current edge; the child entity node identifier is the node identifier of the child entity node corresponding to the current edge; the parent-child entity relationship type is a preset entity relationship type;
[0012] The first data set is composed of a plurality of first data records; the first data record includes a first training text and a first label entity triple; when the first label entity triple is not empty, it is composed of a first label parent entity attribute, a first label child entity attribute and a first label parent-child relationship type; the first label parent entity attribute includes a first label parent entity role and a first label parent entity type; the first label child entity attribute includes a first label child entity role and a first label child entity type; the first label parent entity type and the first label child entity type each correspond to a class of preset entity concept types, and the first parent-child relationship type corresponds to a class of preset entity relationship types;
[0013] The question and answer instruction template is a formatted text configuration template; the question and answer instruction template is used to use the current question text and the current knowledge text as the corresponding original question text and prompt information text; and to inform the first language model through a preset narrative text to use the prompt information text as reference information to generate the corresponding answer text for the question given by the original question text and output the generated answer text.
[0014] Preferably, the first language model includes at least a GPT series model and a BERT series model;
[0015] The first large language model performs corresponding natural language text generation processing based on the natural language understanding of the first instruction text input to the model and outputs the corresponding first generated text; the language model input end of the first large language model is used to receive the first instruction text, and the language model output end is used to output the corresponding first generated text;
[0016] The internal model component of the first large language model at least includes a first word segmentation module, a first word embedding encoding module, a first feature extraction module and a first text generator module; the input end of the first word segmentation module is connected to the input end of the language model, and the output end is connected to the input end of the first word embedding encoding module; the output end of the first word embedding encoding module is connected to the input end of the first feature extraction module; the output end of the first feature extraction module is connected to the input end of the first text generator module; the output end of the first text generator module is connected to the output end of the language model;
[0017] The first word segmentation module is used to perform word segmentation processing on the first instruction text to generate a corresponding first word segmentation sequence and send it to the first word embedding encoding module; the first word segmentation sequence is formed by sequentially sorting a plurality of first word segmentations;
[0018] The first word embedding encoding module is used to perform word embedding encoding processing on each of the first word segmentations in the first word segmentation sequence to obtain a corresponding first word segmentation encoding tensor and send it to the first feature extraction module; the first word segmentation encoding tensor is formed by sequentially sorting a plurality of first word segmentation encoding vectors, and the first word segmentation encoding vectors correspond to the first word segmentations one by one;
[0019] The first feature extraction module is implemented based on the Encoder or Decoder component structure of the Transformer model; the first feature extraction module is used to perform deep learning on the associated features of each word segmentation encoding vector and other word segmentation encoding vectors in the first word segmentation encoding tensor to obtain a corresponding first feature tensor and send it to the first text generator module; the first feature tensor is composed of multiple first feature vectors, and the first feature vector corresponds to the first word segmentation one by one;
[0020] The first text generator module is implemented based on a type of text generator model structure; it is used to perform feature decoding and text generation processing according to the first feature tensor to obtain the corresponding first generated text and output it.
[0021] Preferably, the entity extraction model is used to perform entity triple extraction processing on the first text to be extracted input into the model and output the corresponding first entity triple; when the first entity triple is not empty, it is composed of a first parent entity attribute, a first child entity attribute and a first parent-child relationship type; the first parent entity attribute includes a first parent entity role and a first parent entity type; the first child entity attribute includes a first child entity role and a first child entity type; the first parent entity type and the first child entity type each correspond to a class of preset entity concept types, and the first parent-child relationship type corresponds to a class of preset entity relationship types;
[0022] The extraction model input end of the entity extraction model is used to receive the first text to be extracted, and the extraction model output end is used to output the corresponding first entity triple;
[0023] The internal model component of the entity extraction model is composed of the first word segmentation module, the first word embedding encoding module and the first feature extraction module of the first large language model, and the first fully connected network, the first softmax layer, the first parent-child entity recognition module, the first word segmentation relevance score calculation module, the first relationship feature vector recognition module, the second fully connected network, the second softmax layer, the first relationship type recognition module and the first triple fusion module.
[0024] The connection relationship of the internal model components of the entity extraction model is as follows: the input end of the first word segmentation module is connected to the input end of the extraction model, and the output end is respectively connected to the input end of the first word embedding encoding module and the third input end of the first triple fusion module; the output end of the first word embedding encoding module is connected to the input end of the first feature extraction module; the output end of the first feature extraction module is respectively connected to the input end of the first fully connected network, the second input end of the first word segmentation relevance score calculation module and the second input end of the first relationship feature vector recognition module; the output end of the first fully connected network is connected to the input end of the first softmax layer; the output end of the first softmax layer is connected to the input end of the first parent-child entity recognition module; The output end of a parent-child entity recognition module is respectively connected to the first input end of the first word segmentation relevance score calculation module and the first input end of the first triple fusion module; the output end of the first word segmentation relevance score calculation module is connected to the first input end of the first relationship feature vector recognition module; the output end of the first relationship feature vector recognition module is connected to the input end of the second fully connected network; the output end of the second fully connected network is connected to the input end of the second softmax layer; the output end of the second softmax layer is connected to the input end of the first relationship type recognition module; the output end of the first relationship type recognition module is connected to the second input end of the first triple fusion module; the output end of the first triple fusion module is connected to the output end of the extraction model;
[0025] The first word segmentation module of the entity extraction model is used to perform word segmentation processing on the first text to be extracted to generate a corresponding second word segmentation sequence S and send it to the first word embedding encoding module and the first triple fusion module; the second word segmentation sequence S consists of multiple second word segmentations s i The index i is sorted in order, 1≤partition index i≤N, and N is the total number of participles in the second participle sequence S;
[0026] The first word embedding encoding module of the entity extraction model is used to encode each second word s of the second word sequence S i The word embedding encoding process is performed to obtain the corresponding second word segmentation encoding tensor X, which is sent to the first feature extraction module; the second word segmentation encoding tensor X is composed of N second word segmentation encoding vectors x i The second word segmentation encoding vector x i With the second participle s i One-to-one correspondence; the second word segmentation encoding vector x i The vector length is the preset encoding vector length threshold L hold ;
[0027] The first feature extraction module of the entity extraction model is used to perform deep learning on the associated features of each word segmentation coding vector in the second word segmentation coding tensor X and other word segmentation coding vectors to obtain the corresponding second feature tensor H and send it to the first fully connected network, the first word segmentation relevance score calculation module and the first relationship feature vector recognition module; the second feature tensor H is composed of N second feature vectors h i The second eigenvector h i With the second participle s i One-to-one correspondence; the second eigenvector h i The length of the vector is L hold ;
[0028] The first fully connected network of the entity extraction model is implemented based on a fully connected layer or multiple fully connected layers connected in sequence; the first fully connected network is used to calculate each of the second feature vectors h of the second feature tensor H through full connection. i Perform the corresponding concept type feature conversion to obtain the corresponding third feature vector a i ; and by the obtained N third eigenvectors a i The corresponding third feature tensor A is sent to the first softmax layer; the third feature tensor A is composed of N third feature vectors a i The third eigenvector a i With the second participle s i One-to-one correspondence; the third eigenvector a i The vector length is M+1, where M is the total number of preset entity concept types;
[0029] The first softmax layer of the entity extraction model is implemented based on a softmax function; the first softmax layer is used to extract the third feature vectors a according to the third feature tensor A. i Perform the corresponding entity concept classification prediction process to obtain the corresponding first prediction probability vector pa i ; and the obtained N first prediction probability vectors pa i The first prediction probability tensor PA is composed of N first prediction probability vectors pa and sent to the first parent-child entity recognition module; the first prediction probability tensor PA is composed of N first prediction probability vectors pa i The first prediction probability vector pa i With the second participle s i One-to-one correspondence; each of the first prediction probability vectors pa i It is composed of M+1 first prediction probabilities, the first M first prediction probabilities correspond one-to-one to the preset M types of entity concepts, and the last one of the first prediction probabilities corresponds to a non-entity concept type;
[0030] The first parent-child entity recognition module of the entity extraction model is used to identify all the first prediction probability vectors pa of the first prediction probability tensor PA i Perform a round of traversal; and in this round of traversal, the first prediction probability vector pa currently traversed i as the corresponding current prediction probability vector; and the first prediction probability with the largest probability value in the current prediction probability vector is taken as the corresponding first maximum probability pa max,i and the first maximum probability pa max,i The corresponding entity concept type or the non-entity concept type is used as the corresponding first type ta i ; and at the end of this round of traversal, all the first type ta that are not the non-entity concept type i According to the first maximum probability pa max,i Arrange the first type sequence in descending order; and count the total number of types in the first type sequence to obtain the corresponding first total number; and identify the first total number; if the first total number is greater than or equal to 2, the first type ta ranked first two in the first type sequence i The corresponding word segmentation index i is recorded as the corresponding first and second indexes, and the smaller index value in the first and second indexes is used as the corresponding parent entity index, and the larger index value is used as the corresponding child entity index, and the first type ta corresponding to the parent and child entity indexes is recorded as i as the corresponding parent entity concept type and child entity concept type; if the first total is less than 2, the corresponding parent and child entity indexes and the parent and child entity concept types are set to null; and the obtained parent entity index and the parent entity concept type form the corresponding parent entity recognition data, and the obtained child entity index and the child entity concept type form the corresponding child entity recognition data, and the obtained parent and child entity recognition data are sent to the first word segmentation relevance score calculation module and the first triple fusion module;
[0031] The first word segmentation relevance score calculation module of the entity extraction model is used to convert the two second feature vectors h corresponding to the parent and child entity indexes of the parent and child entity identification data in the second feature tensor H into i Denote as the corresponding parent entity feature vector and child entity feature vector; and the other N-2 second feature vectors h in the second feature tensor H except the parent and child entity feature vectors iare all recorded as the corresponding other feature vectors; and the vector dot product calculation is performed on each of the other feature vectors and the parent entity feature vector, and the calculation result is used as the corresponding parent entity attention score, and the vector dot product calculation is performed on each of the other feature vectors and the child entity feature vector, and the calculation result is used as the corresponding child entity attention score, and the parent and child entity attention scores corresponding to each of the other feature vectors are added and the calculation result is used as the corresponding first attention score; and the obtained N-2 first attention scores are normalized to obtain the corresponding N-2 normalized attention scores; and the normalized attention scores corresponding to the parent and child entity feature vectors are set to 0; and each of the second feature vectors h in the second feature tensor H is added. i The corresponding normalized attention score is recorded as the corresponding first participle relevance score c i ; and the obtained N first word relevance scores c i The first word segmentation relevance score vector C corresponding to the first relationship feature vector recognition module is sent; the first word segmentation relevance score vector C is composed of N first word segmentation relevance scores c i The first word relevance score c i With the second participle s i One to one correspondence;
[0032] The first relationship feature vector recognition module of the entity extraction model is used to convert the first segmentation relevance score c having the largest score in the first segmentation relevance score vector C into i The corresponding word segmentation index i is used as the corresponding relational word segmentation index; and the second feature vector h corresponding to the relational word segmentation index in the second feature tensor H is used as the corresponding relational word segmentation index. i Send it as the corresponding relation feature vector R to the second fully connected network;
[0033] The second fully connected network of the entity extraction model is implemented based on a single fully connected layer or multiple sequentially connected fully connected layers; the second fully connected network is used to convert the relationship feature vector R into a corresponding entity relationship type feature through a fully connected calculation to obtain a corresponding fourth feature vector B and send it to the second softmax layer; the vector length of the fourth feature vector B is Q, and Q is the total number of preset entity relationship types;
[0034] The second softmax layer of the entity extraction model is implemented based on the softmax function; the second softmax layer is used to perform corresponding entity relationship classification prediction processing according to the fourth feature vector B to obtain the corresponding second prediction probability vector PB and send it to the first relationship type recognition module; the second prediction probability vector PB is composed of Q second prediction probabilities pbj Composition, 1≤indexj≤Q; Q second prediction probabilities pb j One-to-one correspondence with the entity relationship types described in the preset Q class;
[0035] The first relationship type identification module of the entity extraction model is used to convert the second prediction probability vector PB with the largest probability into the second prediction probability vector PB. j The corresponding entity relationship type is sent to the first triple fusion module as the corresponding parent-child entity relationship type;
[0036] The first triple fusion module of the entity extraction model is used to identify whether the parent and child entity recognition data are empty; if the parent and child entity recognition data are empty, the corresponding first entity triple is set to be empty; if the parent and child entity recognition data are not empty, the word segmentation index i in the second word segmentation sequence S is respectively matched with the second word segmentation s corresponding to the parent and child entity indexes in the parent and child entity recognition data i Extract them as the corresponding first parent entity role and the first child entity role, and use the parent and child entity concept types in the parent and child entity identification data as the corresponding first parent entity type and the first child entity type, and the first parent entity role and the first parent entity type form the corresponding first parent entity attribute, and the first child entity role and the first child entity type form the corresponding first child entity attribute, and the parent-child entity relationship type is used as the corresponding first parent-child relationship type, and the obtained first parent entity attribute, the first child entity attribute and the first parent-child relationship type form the corresponding first entity triplet; and output the obtained first entity triplet.
[0037] Preferably, the step of constructing the first knowledge graph in advance through big data collection specifically includes:
[0038] The first original corpus set is obtained by collecting text corpus big data through multiple big data collection channels; and all the first original corpus texts obtained are subjected to text noise reduction, deduplication, compliance verification and correctness verification based on manual or other machine model screening methods; and each of the processed first original corpus texts is subjected to sentence processing based on manual or other machine model sentence segmentation methods to obtain one or more corresponding first sentence texts; and each of the first training texts is subjected to corresponding entity triple recognition based on manual or other machine model recognition methods and the recognized entity triples are used as corresponding first recognition triples; and corresponding knowledge graph nodes and edge objects are constructed based on the parent and child entity information and parent-child entity relationships of all the first recognition triples obtained to obtain the corresponding first knowledge graph; wherein the multiple big data collection channels include at least a public structured entity triple database, a public text corpus, a public network text resource, and public technical standards / textbooks / documents / magazines / journals / paper resources in various fields; the first original corpus set includes multiple first original corpus texts.
[0039] Preferably, the automatic generation of the model training data set of the entity extraction model by the first large language model according to the first knowledge graph to obtain the corresponding first data set specifically includes:
[0040] Step 61, taking the first edge of the first knowledge graph as the corresponding current edge;
[0041] Step 62, extract the node entity concept type and the node entity role of the first node corresponding to the parent entity node identifier of the current edge as the corresponding first label parent entity role and the first label parent entity type to form the corresponding first label parent entity attribute; and extract the node entity concept type and the node entity role of the first node corresponding to the child entity node identifier of the current edge as the corresponding first label child entity role and the first label child entity type to form the corresponding first label child entity attribute; and use the parent-child entity relationship type of the current edge as the corresponding first label parent-child relationship type; and form a corresponding first label entity triple by the first label parent entity attribute, the first label child entity attribute and the first label parent-child relationship type corresponding to the current edge; and bring the first label entity triple into a preset text generation instruction template to perform instruction text splicing to obtain the corresponding current instruction text; and input the current instruction text into the first large language model to perform corresponding creative text generation processing and use the generated text output by the model as the corresponding first training text; and form a corresponding first data record by the first training text corresponding to the current edge and the first label entity triple;
[0042] The text generation instruction template is a formatted text configuration template; the text generation instruction template is used to take the first tag entity triple as the corresponding current entity triple; and inform the first language model through a preset narrative text to generate and output a creative text based on the current entity triple;
[0043] Step 63, identify whether the current edge is the last first edge of the first knowledge graph; if not, extract the next first edge of the first knowledge graph as the new current edge and return to step 62; if so, all the first data records obtained constitute the corresponding first data set.
[0044] Preferably, the training of the entity extraction model based on the first data set specifically includes:
[0045] Step 71, dividing the first data set into two sub-data sets as a corresponding first training set and a first evaluation set based on a preset first division ratio;
[0046] Wherein, both the first training set and the first evaluation set are composed of a plurality of the first data records; the ratio of the total number of records in the first training set and the first evaluation set satisfies the first segmentation ratio;
[0047] Step 72, extracting the first first data record in the first training set as the corresponding current training record;
[0048] Step 73, inputting the first training text of the current training record into the entity extraction model to perform entity triple extraction processing to obtain a corresponding first predicted entity triple;
[0049] Wherein, when the first predicted entity triple is not empty, it is composed of a first predicted parent entity attribute, a first predicted child entity attribute and a first predicted parent-child relationship type; the first predicted parent entity attribute includes a first predicted parent entity role and a first predicted parent entity type; the first predicted child entity attribute includes a first predicted child entity role and a first predicted child entity type;
[0050] Step 74: Substitute the first predicted entity triple and the first label entity triple of the current training record into a preset first model loss function L M ; and the preset first model optimizer moves towards making the first model loss function L M Perform a round of optimization processing on the model parameters of the first and second fully connected networks and the first and second softmax layers of the entity extraction model in the direction of achieving the minimum value;
[0051] Among them, the first model loss function L M for:
[0052] L M =L CE (x Op ,x Ot )+L CE (x Sp ,x St )+L CE (x Rp ,x Rt )+L cosine (x Onp ,x Ont )+L cosine (x Snp ,x Snt );
[0053] L CE () is the cross entropy loss function, L cosine () is the cosine similarity loss function; x Op is the one-hot encoding vector of the entity concept type corresponding to the first predicted parent entity type of the first predicted entity triple; Sp is the one-hot encoding vector of the entity concept type corresponding to the first predicted sub-entity type of the first predicted entity triple; Rp is the one-hot encoding vector of the entity relationship type corresponding to the first predicted parent-child relationship type of the first predicted entity triple; Onp is the N-gram encoding vector corresponding to the first predicted parent entity role of the first predicted entity triple; Snp is the N-gram encoding vector corresponding to the first predicted sub-entity role of the first predicted entity triple; Ot is the one-hot encoding vector of the entity concept type corresponding to the first label parent entity type of the first label entity triple; St is the one-hot encoding vector of the entity concept type corresponding to the first label sub-entity type of the first label entity triple; Rt is the entity relationship type one-hot encoding vector corresponding to the first label parent-child relationship type of the first label entity triple; Ont is the N-gram encoding vector corresponding to the first tag parent entity role of the first tag entity triple; Snt The N-gram encoding vector corresponding to the first label sub-entity role of the first label entity triple;
[0054] The first model optimizer includes at least an SGD optimizer and an ADAM optimizer;
[0055] Step 75, identifying whether the current training record is the last first data record in the first training set; if so, going to step 76; if not, extracting the next first data record in the first training set as the new current training record and returning to step 73;
[0056] Step 76, perform a round of traversal on all the first data records of the first evaluation set; and in this round of traversal, use the first data record currently traversed as the corresponding current evaluation record; and input the first training text of the current evaluation record into the entity extraction model to perform entity triple extraction processing to obtain the corresponding second predicted entity triple; and form a corresponding first prediction-label pair from the second predicted entity triple and the first label entity triple of the current training record; and at the end of this round of traversal, bring all the obtained first prediction-label pairs into the preset first model evaluation function F A Performing calculation to obtain a corresponding first evaluation value;
[0057] Among them, the first model evaluation function F A for:
[0058]
[0059] K is the total number of the first prediction-label pairs, 1≤indexk≤K;
[0060] f e () is MAE error function or MSE error function;
[0061] x Op,k is the one-hot encoding vector of the entity concept type corresponding to the first predicted parent entity type of the kth first prediction-label pair; Sp,k is the one-hot encoding vector of the entity concept type corresponding to the first predicted sub-entity type of the kth first prediction-label pair; Rp,k is the one-hot encoding vector of the entity relationship type corresponding to the first predicted parent-child relationship type of the kth first prediction-label pair; Onp,k is the N-gram encoding vector corresponding to the first predicted parent entity role of the kth first prediction-label pair; Snp,k is the N-gram encoding vector corresponding to the first predicted sub-entity role of the kth first prediction-label pair; x Ot,k is the one-hot encoding vector of the entity concept type corresponding to the first label parent entity type of the kth first prediction-label pair; St,k is the one-hot encoding vector of the entity concept type corresponding to the first label sub-entity type of the kth first prediction-label pair; Rt,kis the one-hot encoding vector of the entity relationship type corresponding to the first label parent-child relationship type of the kth first prediction-label pair; Ont,k is the N-gram encoding vector corresponding to the first label parent entity role of the kth first prediction-label pair; x Snt,k is the N-gram encoding vector corresponding to the first label sub-entity role of the kth first prediction-label pair;
[0062] Step 77, identifying whether the first evaluation value satisfies a preset first evaluation value range; if not, returning to step 72 to continue training; if satisfied, stopping training and confirming that the entity extraction model training is completed.
[0063] Preferably, the performing knowledge retrieval processing according to the current entity triple and the first knowledge graph to obtain the corresponding current knowledge text specifically includes:
[0064] Extracting the corresponding current parent entity role, current parent entity type, current child entity role, current child entity type and current parent-child relationship type from the current entity triplet;
[0065] and taking the first edge in the first knowledge graph, in which the node entity concept type and the node entity role of the first node corresponding to the parent entity node identifier respectively match the current parent entity type and the current parent entity role, and the node entity concept type and the node entity role of the first node corresponding to the child entity node identifier respectively match the current child entity type and the current child entity role, and the parent-child entity relationship type matches the current parent-child relationship type as the corresponding first retrieval edge;
[0066] And identify whether the number of the first search edges is unique; if the number of the first search edges is unique, extract the node entity roles of the parent and child entity nodes corresponding to the current first search edge to form the corresponding first knowledge text; if the number of the first search edges is not unique, extract the node entity roles of the parent and child entity nodes corresponding to the first search edge whose edge update time is closest to the current time to form the corresponding first knowledge text;
[0067] And identify the preset knowledge verification mode; if the knowledge verification mode is a mode that does not require verification, output the first knowledge text as the corresponding current knowledge text; if the knowledge verification mode is a mode that requires verification, verify the correctness of the first knowledge text based on the preset knowledge verification interface to obtain the corresponding first verification result, and when the first verification result is correct, output the first knowledge text as the corresponding current knowledge text; the knowledge verification mode includes a mode that does not require verification and a mode that requires verification; the first verification result includes correct and incorrect.
[0068] A second aspect of an embodiment of the present invention provides a device for implementing the method for processing a question-answering task in combination with a knowledge graph as described in the first aspect, the device comprising: a knowledge graph preparation module, a model building and training module, and a question-answering task processing module;
[0069] The knowledge graph preparation module is used to construct a first knowledge graph in advance through big data collection;
[0070] The model building and training module is used to use a type of large language model that has been pre-trained and fine-tuned as the corresponding first large language model; and customize a processing model for entity triple extraction based on the feature extraction component of the first large language model as the corresponding entity extraction model; and the first large language model automatically generates a model training data set of the entity extraction model according to the first knowledge graph to obtain a corresponding first data set; and train the entity extraction model based on the first data set;
[0071] The question-and-answer task processing module is used to, after the model training is completed, receive the question text input by the user and record it as the corresponding current question text; and the entity extraction model performs entity triple extraction processing on the current question text to obtain the corresponding current entity triplet; and performs knowledge retrieval processing based on the current entity triplet and the first knowledge graph to obtain the corresponding current knowledge text; and brings the current question text and the current knowledge text into a preset question-and-answer instruction template to perform question-and-answer instruction text splicing processing to obtain the corresponding current question-and-answer instruction text; and inputs the current question-and-answer instruction text into the first large language model to perform answer text generation processing to obtain the corresponding current answer text to feedback to the user.
[0072] A third aspect of an embodiment of the present invention provides an electronic device, including: a memory, a processor, and a transceiver;
[0073] The processor is used to couple with the memory, read and execute instructions in the memory, so as to implement the method steps described in the first aspect above;
[0074] The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.
[0075] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions. When the computer instructions are executed by a computer, the computer executes the instructions of the method described in the first aspect above.
[0076] The embodiment of the present invention provides a method, device, electronic device and computer-readable storage medium for processing question-answering tasks in combination with a knowledge graph. As can be seen from the above content, the embodiment of the present invention constructs a knowledge graph in advance through big data collection, and customizes an entity extraction model based on the feature extraction component of a large language model, and the large language model automatically generates and processes the model training data set of the entity extraction model according to the knowledge graph, and trains the entity extraction model based on the generated data set; and in each question-answering task processing process after the model training is completed, the entity extraction model first extracts entity triples from the question text, and then searches the knowledge graph according to the entity triples extracted at that time to obtain the corresponding knowledge text, and then inputs the knowledge text obtained at that time as reference / prompt information together with the question text into the large language model for corresponding answer text generation processing. When processing a question-answering task, the embodiment of the present invention first obtains knowledge information related to the correct answer through knowledge graph retrieval, and then uses the obtained knowledge information to prompt the large language model to generate the corresponding answer text. The embodiment of the present invention can reduce the error rate of the question-answering task and improve the processing performance of the question-answering task. In addition, the embodiment of the present invention does not perform large-scale training on the large language model, but only performs local training on the customized small model. It does not construct a training data set through manual data collection, but only uses the text generation capability of the large model to automatically construct the training data set. The embodiment of the present invention not only shortens the improvement cycle and improves the improvement efficiency, but also greatly reduces the improvement cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] Figure 1 A schematic diagram of a method for processing a question-answering task in combination with a knowledge graph provided in Embodiment 1 of the present invention;
[0078] Figure 2 A schematic diagram of a first node and a first edge provided in Embodiment 1 of the present invention;
[0079] Figure 3 A module structure diagram of the first language model provided in the first embodiment of the present invention;
[0080] Figure 4 A module structure diagram of the entity extraction model provided in the first embodiment of the present invention;
[0081] Figure 5A module structure diagram of a device for processing question-answering tasks in combination with a knowledge graph provided in Embodiment 2 of the present invention;
[0082] Figure 6 A schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0083] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0084] Embodiment 1 of the present invention provides a method for processing question-answering tasks in combination with a knowledge graph, such as Figure 1 As shown in the schematic diagram of a method for processing a question-answering task in combination with a knowledge graph provided in the first embodiment of the present invention, the method mainly includes the following steps:
[0085] Step 1: construct the first knowledge graph by collecting big data in advance;
[0086] The first knowledge graph is composed of a first node set and a first edge set; the first node set includes a plurality of first nodes; the first edge set includes a plurality of first edges;
[0087] Each first node corresponds to an entity; Figure 2 As shown in the schematic diagram of the first node and the first edge provided in the first embodiment of the present invention, the node attributes of each first node include a node identifier, a node update time, a node entity concept type, a node entity role and a node entity attribute set; the node identifier is a unique identifier of the current node; the node update time is the latest addition or update time of the current node; the node entity concept type is a class of preset entity concept types, such as people, places, time, animals, plants, etc.; the node entity role is a specific role parameter of the entity corresponding to the current node, for example, when the node entity concept type is a person, the node entity role is actually the name information, when the node entity concept type is a place, the node entity role is actually the place name information, when the node entity concept type is time, the node entity role is actually the time information, and when the node entity concept type is an animal / plant, the node entity role is actually the name information of an animal / plant;
[0088] Each first edge is a directed edge; the starting node of each first edge is recorded as the parent entity node, and the ending node is recorded as the child entity node; Figure 2As shown, the edge attributes of the first edge include edge identifier, edge update time, parent entity node identifier, child entity node identifier and parent-child entity relationship type; the edge identifier is the unique identifier of the current edge; the edge update time is the latest addition or update time of the current edge; the parent entity node identifier is the node identifier of the parent entity node corresponding to the current edge; the child entity node identifier is the node identifier of the child entity node corresponding to the current edge; the parent-child entity relationship type is a type of preset entity relationship type, for example, the parent entity node points to a person's name, the child entity node points to a time, then the corresponding parent-child entity relationship type may be a time-related relationship type such as "birthday";
[0089] The current step 1 specifically includes: collecting text corpus big data through multiple big data collection channels to obtain the corresponding first original corpus set; and performing text noise reduction, deduplication, compliance inspection and correctness inspection processing on all the first original corpus texts obtained based on manual or other machine model screening methods; and performing sentence processing on each processed first original corpus text based on manual or other machine model sentence segmentation methods to obtain one or more corresponding first sentence texts; and performing corresponding entity triple recognition on each first training text based on manual or other machine model recognition methods and using the recognized entity triples as corresponding first recognition triples; and constructing corresponding knowledge graph nodes and edge objects based on the parent and child entity information and parent-child entity relationships of all the first recognition triples obtained to obtain the corresponding first knowledge graph;
[0090] Among them, the various big data collection channels include at least public structured entity triple databases, public text corpora, public network text resources, and public technical standards / textbooks / documents / magazines / journals / paper resources in various fields; the first original corpus set includes multiple first original corpus texts.
[0091] Step 2: a large language model that has been pre-trained and fine-tuned is used as the corresponding first large language model; a processing model for entity triple extraction is customized based on the feature extraction component of the first large language model and recorded as the corresponding entity extraction model; the first large language model automatically generates a model training data set of the entity extraction model according to the first knowledge graph to obtain a corresponding first data set; and the entity extraction model is trained based on the first data set;
[0092] Specifically, it includes: step 21, taking a type of large language model that has completed pre-training and fine-tuning as the corresponding first large language model;
[0093] Here, the first language model of the embodiment of the present invention includes at least a GPT series model and a BERT series model; wherein, when processing a text generation task, the GPT series model uses the Decoder module of the Transformer model as the feature extraction module, and the corresponding text generator performs corresponding feature decoding and text generation processing according to the output features of the feature extraction module, and when processing a text generation task, the BERT series model uses the Encoder module of the Transformer model as the feature extraction module, and the corresponding text generator performs corresponding feature decoding and text generation processing according to the output features of the feature extraction module;
[0094] In terms of model function, the first language model of the embodiment of the present invention performs corresponding natural language text generation processing based on the natural language understanding of the first instruction text input to the model and outputs the corresponding first generated text; Figure 3 As shown in the module structure diagram of the first large language model provided in the first embodiment of the present invention, the language model input end of the first large language model is used to receive the first instruction text, and the language model output end is used to output the corresponding first generated text;
[0095] like Figure 3 As shown, the internal model components of the first large language model at least include a first word segmentation module, a first word embedding encoding module, a first feature extraction module and a first text generator module;
[0096] The connection relationship of the internal model components is as follows: the input end of the first word segmentation module is connected to the input end of the language model, and the output end is connected to the input end of the first word embedding encoding module; the output end of the first word embedding encoding module is connected to the input end of the first feature extraction module; the output end of the first feature extraction module is connected to the input end of the first text generator module; the output end of the first text generator module is connected to the output end of the language model;
[0097] The component functions of the internal model components are:
[0098] 1) The first word segmentation module is used to perform word segmentation processing on the first instruction text to generate a corresponding first word segmentation sequence and send it to the first word embedding encoding module; wherein the first word segmentation sequence is formed by sequentially sorting a plurality of first word segmentations;
[0099] 2) The first word embedding coding module is used to perform word embedding coding processing on each first word of the first word segmentation sequence to obtain a corresponding first word segmentation coding tensor and send it to the first feature extraction module; wherein the first word segmentation coding tensor is formed by sequentially sorting a plurality of first word segmentation coding vectors, and the first word segmentation coding vectors correspond to the first word segmentation one by one;
[0100] 3) The first feature extraction module is implemented based on the Encoder or Decoder component structure of the Transformer model; the first feature extraction module is used to perform deep learning on the associated features of each word segmentation encoding vector and other word segmentation encoding vectors in the first word segmentation encoding tensor to obtain the corresponding first feature tensor and send it to the first text generator module; wherein the first feature tensor is composed of multiple first feature vectors, and the first feature vector corresponds to the first word segmentation one by one;
[0101] 4) The first text generator module is implemented based on a type of text generator model structure; the first text generator module is used to perform feature decoding and text generation processing according to the first feature tensor to obtain a corresponding first generated text and output it;
[0102] Step 22, a processing model for extracting entity triples is customized based on the feature extraction component of the first language model and recorded as a corresponding entity extraction model;
[0103] Here, the entity extraction model of the embodiment of the present invention is used to perform entity triple extraction processing on the first text to be extracted input by the model and output the corresponding first entity triple; wherein, when the first entity triple is not empty, it is composed of a first parent entity attribute, a first child entity attribute and a first parent-child relationship type; the first parent entity attribute includes a first parent entity role and a first parent entity type; the first child entity attribute includes a first child entity role and a first child entity type; the first parent entity type and the first child entity type each correspond to a class of preset entity concept types, and the first parent-child relationship type corresponds to a class of preset entity relationship types;
[0104] like Figure 4 As shown in the module structure diagram of the entity extraction model provided in the first embodiment of the present invention, the extraction model input end of the entity extraction model in the embodiment of the present invention is used to receive the first text to be extracted, and the extraction model output end is used to output the corresponding first entity triple;
[0105] The internal model component of the entity extraction model is composed of a first word segmentation module, a first word embedding encoding module and a first feature extraction module of a first large language model, and an additionally configured first fully connected network, a first softmax layer, a first parent-child entity recognition module, a first word segmentation relevance score calculation module, a first relationship feature vector recognition module, a second fully connected network, a second softmax layer, a first relationship type recognition module and a first triple fusion module;
[0106] The connection relationship of the internal model components is: the input end of the first word segmentation module is connected to the input end of the extraction model, and the output end is respectively connected to the input end of the first word embedding coding module and the third input end of the first triple fusion module; the output end of the first word embedding coding module is connected to the input end of the first feature extraction module; the output end of the first feature extraction module is respectively connected to the input end of the first fully connected network, the second input end of the first word segmentation relevance score calculation module and the second input end of the first relationship feature vector recognition module; the output end of the first fully connected network is connected to the input end of the first softmax layer; the output end of the first softmax layer is connected to the input end of the first parent-child entity recognition module; the first parent-child entity The output end of the recognition module is connected to the first input end of the first word segmentation relevance score calculation module and the first input end of the first triple fusion module respectively; the output end of the first word segmentation relevance score calculation module is connected to the first input end of the first relationship feature vector recognition module; the output end of the first relationship feature vector recognition module is connected to the input end of the second fully connected network; the output end of the second fully connected network is connected to the input end of the second softmax layer; the output end of the second softmax layer is connected to the input end of the first relationship type recognition module; the output end of the first relationship type recognition module is connected to the second input end of the first triple fusion module; the output end of the first triple fusion module is connected to the output end of the extraction model;
[0107] The component functions of the internal model components are:
[0108] 1) The first word segmentation module is used to perform word segmentation processing on the first text to be extracted to generate a corresponding second word segmentation sequence S and send it to the first word embedding encoding module and the first triple fusion module;
[0109] Among them, the second participle sequence S consists of multiple second participles s i Sorted in order, 1≤partition index i≤N, N is the total number of participles in the second participle sequence S;
[0110] 2) The first word embedding encoding module is used to encode each second word s of the second word sequence S i Perform word embedding encoding processing to obtain the corresponding second word segmentation encoding tensor X and send it to the first feature extraction module;
[0111] Among them, the second word segmentation encoding tensor X is composed of N second word segmentation encoding vectors x i Composition, the second word segmentation encoding vector x i With the second participle s i One-to-one correspondence; second word segmentation encoding vector x i The vector length is the preset encoding vector length threshold L hold ;
[0112] 3) The first feature extraction module is used to perform deep learning on the associated features of each word segmentation coding vector and other word segmentation coding vectors in the second word segmentation coding tensor X to obtain the corresponding second feature tensor H and send it to the first fully connected network, the first word segmentation relevance score calculation module and the first relationship feature vector recognition module;
[0113] Among them, the second eigentensor H is composed of N second eigenvectors h i The second eigenvector h i With the second participle s i One-to-one correspondence; the second eigenvector h i The length of the vector is L hold ;
[0114] 4) The first fully connected network is implemented based on a fully connected layer or multiple layers of sequentially connected fully connected layers; the first fully connected network is used to calculate each second feature vector h of the second feature tensor H through full connection i Perform the corresponding concept type feature conversion to obtain the corresponding third feature vector a i ; and the N third eigenvectors a obtained i The corresponding third feature tensor A is sent to the first softmax layer;
[0115] Among them, the third eigentensor A is composed of N third eigenvectors a i The third eigenvector a i With the second participle s i One-to-one correspondence; the third eigenvector a i The vector length is M+1, where M is the total number of preset entity concept types;
[0116] 5) The first softmax layer is implemented based on the softmax function; the first softmax layer is used to calculate the third eigenvectors a of the third eigentensor A according to the third eigenvectors a of the third eigentensor A. i Perform the corresponding entity concept classification prediction process to obtain the corresponding first prediction probability vector pa i ; and the obtained N first prediction probability vectors pa i The corresponding first prediction probability tensor PA is sent to the first parent-child entity recognition module;
[0117] Among them, the first prediction probability tensor PA is composed of N first prediction probability vectors pa i The first prediction probability vector pa i With the second participle s i One-to-one correspondence; each first prediction probability vector pa i It consists of M+1 first prediction probabilities, the first M first prediction probabilities correspond one-to-one to the preset M types of entity concepts, and the last first prediction probability corresponds to a non-entity concept type;
[0118] 6) The first parent-child entity recognition module is used to identify all first prediction probability vectors pa of the first prediction probability tensor PA i Perform a round of traversal; and in this round of traversal, the first prediction probability vector pa currently traversed i as the corresponding current prediction probability vector; and the first prediction probability with the largest probability value in the current prediction probability vector is taken as the corresponding first maximum probability pa max,i , and the first maximum probability pa max,i The corresponding entity concept type or non-entity concept type is used as the corresponding first type ta i ; and at the end of this round of traversal, all the first types ta that are not non-entity concept types i According to the first maximum probability pa max,i Sort the first type sequence in descending order; and count the total number of types in the first type sequence to obtain the corresponding first total number; and identify the first total number; if the first total number is greater than or equal to 2, the first type ta ranked first two in the first type sequence i The corresponding word segmentation index i is recorded as the corresponding first and second indexes, and the smaller index value in the first and second indexes is used as the corresponding parent entity index, and the larger index value is used as the corresponding child entity index, and the first type ta corresponding to the parent and child entity indexes is recorded as i as the corresponding parent entity concept type and child entity concept type; if the first total is less than 2, the corresponding parent and child entity indexes and parent and child entity concept types are set to null; and the corresponding parent entity recognition data is composed of the obtained parent entity index and parent entity concept type, and the corresponding child entity recognition data is composed of the obtained child entity index and child entity concept type, and the obtained parent and child entity recognition data is sent to the first word segmentation relevance score calculation module and the first triple fusion module;
[0119] 7) The first word segmentation relevance score calculation module is used to convert the two second feature vectors h corresponding to the parent and child entity indexes of the parent and child entity identification data in the second feature tensor H into i Denote as the corresponding parent entity feature vector and child entity feature vector; and the other N-2 second feature vectors h in the second feature tensor H except the parent and child entity feature vectors iare all recorded as the corresponding other eigenvectors; and the vector dot product calculation is performed on each other eigenvector and the parent entity eigenvector, and the calculation result is used as the corresponding parent entity attention score, and the vector dot product calculation is performed on each other eigenvector and the child entity eigenvector, and the calculation result is used as the corresponding child entity attention score, and the parent and child entity attention scores corresponding to each other eigenvector are added and calculated, and the calculation result is used as the corresponding first attention score; and the obtained N-2 first attention scores are normalized to obtain the corresponding N-2 normalized attention scores; and the normalized attention scores corresponding to the parent and child entity eigenvectors are set to 0; and each second eigenvector h in the second eigentensor H is added. i The corresponding normalized attention score is recorded as the corresponding first participle relevance score c i ; and the obtained N first participle relevance scores c i The first word segmentation relevance score vector C corresponding to the first relationship feature vector recognition module is sent;
[0120] Among them, the first participle relevance score vector C is composed of N first participle relevance scores c i Composition, first participle relevance score c i With the second participle s i One to one correspondence;
[0121] 8) The first relationship feature vector recognition module is used to convert the first segmentation relevance score c with the largest score in the first segmentation relevance score vector C into i The corresponding word segmentation index i is used as the corresponding relational word segmentation index; and the second feature vector h corresponding to the relational word segmentation index in the second feature tensor H is used. i Send it as the corresponding relation feature vector R to the second fully connected network;
[0122] 9) The second fully connected network is implemented based on a fully connected layer or multiple layers of sequentially connected fully connected layers; the second fully connected network is used to convert the relationship feature vector R into the corresponding entity relationship type feature through fully connected calculation to obtain the corresponding fourth feature vector B and send it to the second softmax layer;
[0123] Wherein, the vector length of the fourth characteristic vector B is Q, and Q is the total number of preset entity relationship types;
[0124] 10) The second softmax layer is implemented based on the softmax function; the second softmax layer is used to perform corresponding entity relationship classification prediction processing according to the fourth feature vector B to obtain the corresponding second prediction probability vector PB and send it to the first relationship type recognition module;
[0125] Among them, the second prediction probability vector PB is composed of Q second prediction probabilities pb jComposition, 1≤indexj≤Q; Q second prediction probabilities pb j One-to-one correspondence with the preset Q-type entity relationship type;
[0126] 11) The first relationship type identification module is used to convert the second prediction probability vector PB with the largest probability into the second prediction probability vector PB. j The corresponding entity relationship type is sent to the first triple fusion module as the corresponding parent-child entity relationship type;
[0127] 12) The first triple fusion module is used to identify whether the parent and child entity recognition data are empty; if the parent and child entity recognition data are empty, the corresponding first entity triple is set to be empty; if the parent and child entity recognition data are not empty, the second word segmentation index i in the second word segmentation sequence S is respectively matched with the second word segmentation s corresponding to the parent and child entity indexes in the parent and child entity recognition data. i Extract them as the corresponding first parent entity role and first child entity role, and use the parent and child entity concept types in the parent and child entity identification data as the corresponding first parent entity type and first child entity type, and use the first parent entity role and the first parent entity type to form the corresponding first parent entity attribute, and use the first child entity role and the first child entity type to form the corresponding first child entity attribute, and use the parent-child entity relationship type as the corresponding first parent-child relationship type, and use the obtained first parent entity attribute, first child entity attribute and first parent-child relationship type to form the corresponding first entity triple; and output the obtained first entity triple;
[0128] Step 23, the first large language model automatically generates a model training data set of the entity extraction model according to the first knowledge graph to obtain a corresponding first data set;
[0129] Wherein, the first data set is composed of multiple first data records; the first data record includes a first training text and a first label entity triple; when the first label entity triple is not empty, it is composed of a first label parent entity attribute, a first label child entity attribute and a first label parent-child relationship type; the first label parent entity attribute includes a first label parent entity role and a first label parent entity type; the first label child entity attribute includes a first label child entity role and a first label child entity type; the first label parent entity type and the first label child entity type each correspond to a class of preset entity concept types, and the first parent-child relationship type corresponds to a class of preset entity relationship types;
[0130] Specifically comprising: step 231, taking the first first edge of the first knowledge graph as the corresponding current edge;
[0131] Step 232, extract the node entity concept type and node entity role of the first node corresponding to the parent entity node identifier of the current edge as the corresponding first label parent entity role and the first label parent entity type to form the corresponding first label parent entity attribute; and extract the node entity concept type and node entity role of the first node corresponding to the child entity node identifier of the current edge as the corresponding first label child entity role and the first label child entity type to form the corresponding first label child entity attribute; and use the parent-child entity relationship type of the current edge as the corresponding first label parent-child relationship type; and form a corresponding first label entity triple by the first label parent entity attribute, the first label child entity attribute and the first label parent-child relationship type corresponding to the current edge; and bring the first label entity triple into a preset text generation instruction template to perform instruction text splicing to obtain the corresponding current instruction text; and input the current instruction text into the first large language model to perform corresponding creative text generation processing and use the generated text output by the model as the corresponding first training text; and form a corresponding first data record by the first training text corresponding to the current edge and the first label entity triple;
[0132] The text generation instruction template is a formatted text configuration template; the text generation instruction template is used to take the first label entity triple as the corresponding current entity triple; and inform the first language model through a preset narrative text to generate a creative text based on the current entity triple and output it;
[0133] Step 233, identifying whether the current edge is the last first edge of the first knowledge graph; if not, extracting the next first edge of the first knowledge graph as the new current edge and returning to step 232; if yes, forming a corresponding first data set from all the first data records obtained;
[0134] Step 24, training the entity extraction model based on the first data set;
[0135] Specifically, it includes: step 241, dividing the first data set into two sub-data sets as a corresponding first training set and a first evaluation set based on a preset first division ratio;
[0136] The first segmentation ratio is a preset ratio value, such as 8:2; the first training set and the first evaluation set are both composed of a plurality of first data records; the ratio of the total number of records in the first training set and the first evaluation set satisfies the first segmentation ratio;
[0137] Step 242, extracting the first first data record in the first training set as the corresponding current training record;
[0138] Step 243, inputting the first training text of the current training record into the entity extraction model to perform entity triple extraction processing to obtain the corresponding first predicted entity triple;
[0139] Wherein, when the first predicted entity triple is not empty, it is composed of a first predicted parent entity attribute, a first predicted child entity attribute, and a first predicted parent-child relationship type; the first predicted parent entity attribute includes a first predicted parent entity role and a first predicted parent entity type; the first predicted child entity attribute includes a first predicted child entity role and a first predicted child entity type;
[0140] Step 244: Substitute the first predicted entity triple and the first label entity triple of the current training record into the preset first model loss function L M ; and the preset first model optimizer moves towards making the first model loss function L M A round of optimization processing is performed on the model parameters of the first and second fully connected networks and the first and second softmax layers of the entity extraction model in the direction of achieving the minimum value;
[0141] Here, the first model loss function L of the embodiment of the present invention is M for:
[0142] L M =L CE (x Op ,x Ot )+L CE (x Sp ,x St )+L CE (x RP ,x Rt )+L cosine (x Onp ,x Ont )+L csine (x Snp ,x Snt );
[0143] Among them, L CE () is the cross entropy loss function, L cosine () is the cosine similarity loss function; x Op is the one-hot encoding vector of the entity concept type corresponding to the first predicted parent entity type of the first predicted entity triple; Sp is the one-hot encoding vector of the entity concept type corresponding to the first predicted sub-entity type of the first predicted entity triple; Rp is the entity relationship type one-hot encoding vector corresponding to the first predicted parent-child relationship type of the first predicted entity triple; x Onp is the N-gram encoding vector corresponding to the first predicted parent entity role of the first predicted entity triple; Snpis the N-gram encoding vector corresponding to the first predicted sub-entity role of the first predicted entity triple; Ot is the entity concept type one-hot encoding vector corresponding to the first label parent entity type of the first label entity triple; x St is the entity concept type one-hot encoding vector corresponding to the first label sub-entity type of the first label entity triple; Rt is the entity relationship type one-hot encoding vector corresponding to the first label parent-child relationship type of the first label entity triple; x Ont is the N-gram encoding vector corresponding to the first label parent entity role of the first label entity triple; x Snt The N-gram encoding vector corresponding to the first label sub-entity role of the first label entity triple;
[0144] The first model optimizer of the embodiment of the present invention includes at least an SGD optimizer and an ADAM optimizer;
[0145] Step 245, identifying whether the current training record is the last first data record in the first training set; if so, going to step 246; if not, extracting the next first data record in the first training set as the new current training record and returning to step 243;
[0146] Step 246, perform a round of traversal on all first data records of the first evaluation set; and in this round of traversal, use the first data record currently traversed as the corresponding current evaluation record; and input the first training text of the current evaluation record into the entity extraction model to perform entity triple extraction processing to obtain the corresponding second predicted entity triple; and form a corresponding first prediction-label pair from the second predicted entity triple and the first label entity triple of the current training record; and at the end of this round of traversal, bring all the obtained first prediction-label pairs into the preset first model evaluation function F A Performing calculation to obtain a corresponding first evaluation value;
[0147] Here, the first model evaluation function F of the embodiment of the present invention is A for:
[0148]
[0149] in,
[0150] K is the total number of first prediction-label pairs, 1≤indexk≤K;
[0151] f e () is MAE error function or MSE error function;
[0152] x Op,kis the one-hot encoding vector of the entity concept type corresponding to the first predicted parent entity type of the kth first prediction-label pair; Sp,k is the entity concept type one-hot encoding vector corresponding to the first predicted sub-entity type of the kth first prediction-label pair; x Rp,k is the one-hot encoding vector of the entity relationship type corresponding to the first predicted parent-child relationship type of the kth first prediction-label pair; x Onp,k is the N-gram encoding vector corresponding to the first predicted parent entity role of the kth first prediction-label pair; Snp,k is the N-gram encoding vector corresponding to the first predicted sub-entity role of the kth first prediction-label pair; x Ot,k is the entity concept type one-hot encoding vector corresponding to the first label parent entity type of the kth first prediction-label pair; x St,k is the entity concept type one-hot encoding vector corresponding to the first label sub-entity type of the kth first prediction-label pair; Rt,k is the entity relationship type one-hot encoding vector corresponding to the first label parent-child relationship type of the kth first prediction-label pair; x Ont,k is the N-gram encoding vector corresponding to the first label parent entity role of the kth first prediction-label pair; Snt,k is the N-gram encoding vector corresponding to the first label sub-entity role of the kth first prediction-label pair;
[0153] Step 247, identifying whether the first evaluation value satisfies a preset first evaluation value range; if not, returning to step 242 to continue training; if satisfied, stopping training and confirming that the entity extraction model training is completed.
[0154] Here, the first evaluation value is a preset evaluation value range.
[0155] Step 3, after the model training is completed, the question text input by the user is received and recorded as the corresponding current question text; the entity extraction model performs entity triple extraction processing on the current question text to obtain the corresponding current entity triple; and performs knowledge retrieval processing based on the current entity triple and the first knowledge graph to obtain the corresponding current knowledge text; and the current question text and the current knowledge text are brought into the preset question and answer instruction template to perform question and answer instruction text splicing processing to obtain the corresponding current question and answer instruction text; and the current question and answer instruction text is input into the first language model to perform answer text generation processing to obtain the corresponding current answer text and feedback to the user;
[0156] Specifically, it includes: step 31, after the model training is completed, the question text input by the user is received and recorded as the corresponding current question text;
[0157] Step 32, the entity extraction model performs entity triple extraction processing on the current question text to obtain the corresponding current entity triple;
[0158] Step 33, performing knowledge retrieval processing based on the current entity triple and the first knowledge graph to obtain the corresponding current knowledge text;
[0159] Specifically, it includes: step 331, extracting the corresponding current parent entity role, current parent entity type, current child entity role, current child entity type and current parent-child relationship type from the current entity triple;
[0160] Step 332, and take the first edge in the first knowledge graph, in which the node entity concept type and the node entity role of the first node corresponding to the parent entity node identifier respectively match the current parent entity type and the current parent entity role, and the node entity concept type and the node entity role of the first node corresponding to the child entity node identifier respectively match the current child entity type and the current child entity role, and the parent-child entity relationship type matches the current parent-child relationship type as the corresponding first search edge;
[0161] Step 333, and identify whether the number of the first search edges is unique; if the number of the first search edges is unique, extract the node entity roles of the parent and child entity nodes corresponding to the current first search edge to form the corresponding first knowledge text; if the number of the first search edges is not unique, extract the node entity roles of the parent and child entity nodes corresponding to the first search edge whose edge update time is closest to the current time to form the corresponding first knowledge text;
[0162] Step 334, and identify the preset knowledge verification mode; if the knowledge verification mode is a mode that does not require verification, the first knowledge text is output as the corresponding current knowledge text; if the knowledge verification mode is a mode that requires verification, the correctness of the first knowledge text is verified based on the preset knowledge verification interface to obtain a corresponding first verification result, and when the first verification result is correct, the first knowledge text is output as the corresponding current knowledge text;
[0163] The knowledge verification mode includes a no-verification mode and a verification-required mode; the first verification result includes correct and incorrect;
[0164] Here, the knowledge verification interface is a pre-set processing interface for automatically performing knowledge verification tasks, and the processing interface may be another processing interface for performing knowledge query based on other knowledge graphs and comparing / verifying the query knowledge, or another processing interface for performing knowledge query based on other databases or text corpora and comparing / verifying the query knowledge, or another processing interface for performing knowledge query based on other large language models and comparing / verifying the query knowledge;
[0165] Step 34, the current question text and the current knowledge text are brought into a preset question and answer instruction template to perform question and answer instruction text splicing processing to obtain the corresponding current question and answer instruction text;
[0166] Here, the question-answer instruction template of the embodiment of the present invention is a formatted text configuration template; the question-answer instruction template is used to use the current question text and the current knowledge text as the corresponding original question text and prompt information text; and to inform the first language model through a preset narrative text to use the prompt information text as reference information to generate the corresponding answer text for the question given in the original question text and output the generated answer text;
[0167] Step 35, the current question and answer instruction text is input into the first language model for answer text generation processing to obtain the corresponding current answer text and feedback it to the user.
[0168] Figure 5 The module structure diagram of a device for processing question-answering tasks in combination with a knowledge graph provided in the second embodiment of the present invention, the device is a terminal device or server that implements the aforementioned method embodiment, and can also be a device that enables the aforementioned terminal device or server to implement the aforementioned method embodiment, for example, the device can be a device or chip system of the aforementioned terminal device or server. Figure 5 As shown, the device includes: a knowledge graph preparation module 201, a model building and training module 202 and a question and answer task processing module 203.
[0169] The knowledge graph preparation module 201 is used to construct the first knowledge graph in advance through big data collection.
[0170] The model building and training module 202 is used to take a type of large language model that has completed pre-training and fine-tuning as the corresponding first large language model; and customize a processing model for entity triple extraction based on the feature extraction component of the first large language model as the corresponding entity extraction model; and the first large language model automatically generates and processes the model training data set of the entity extraction model according to the first knowledge graph to obtain the corresponding first data set; and train the entity extraction model based on the first data set.
[0171] The question-answering task processing module 203 is used to receive the question text input by the user after the model training is completed, record it as the corresponding current question text; and use the entity extraction model to perform entity triple extraction processing on the current question text to obtain the corresponding current entity triplet; and perform knowledge retrieval processing based on the current entity triplet and the first knowledge graph to obtain the corresponding current knowledge text; and bring the current question text and the current knowledge text into the preset question-answering instruction template to perform question-answering instruction text splicing processing to obtain the corresponding current question-answering instruction text; and input the current question-answering instruction text into the first language model to perform answer text generation processing to obtain the corresponding current answer text and feedback to the user.
[0172] An embodiment of the present invention provides a device for processing question-answering tasks in combination with a knowledge graph, which can execute the method steps in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0173] It should be noted that it should be understood that the division of the various modules of the above devices is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the knowledge graph preparation module can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the above-mentioned module is determined. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in software form.
[0174] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital signal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module above is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0175] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented 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, all or part of the processes or functions described in the above method embodiments are generated. The above computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The above-mentioned computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the above-mentioned computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, Bluetooth, microwave, etc.) methods. The above-mentioned computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The above-mentioned available medium can be a magnetic medium (such as a floppy disk, a hard disk, a tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0176] Figure 6 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. The electronic device may be a terminal device or a server for implementing the method of the aforementioned embodiment, or may be a terminal device or a server for implementing the method of the aforementioned embodiment connected to the aforementioned terminal device or server. Figure 6As shown, the electronic device may include: a processor 301 (such as a CPU), a memory 302, and a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transceiver 303. Various instructions may be stored in the memory 302 to complete various processing functions and implement the processing steps described in the aforementioned embodiment method. Preferably, the electronic device involved in the embodiment of the present invention also includes: a power supply 304, a system bus 305 and a communication port 306. The system bus 305 is used to realize the communication connection between components. The above-mentioned communication port 306 is used for connecting and communicating between the electronic device and other peripherals.
[0177] exist Figure 6 The system bus 305 mentioned in the figure can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used to realize the communication between the database access device and other devices (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM), and may also include non-volatile memory (Non-Volatile Memory), such as at least one disk storage.
[0178] The above-mentioned processor can be a general-purpose processor, including a central processing unit CPU, a network processor (Network Processor, NP), a graphics processing unit (Graphics Processing Unit, GPU), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0179] It should be noted that an embodiment of the present invention further provides a computer-readable storage medium, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the method and processing process provided in the above embodiments.
[0180] The embodiment of the present invention provides a method, device, electronic device and computer-readable storage medium for processing question-answering tasks in combination with a knowledge graph. As can be seen from the above content, the embodiment of the present invention constructs a knowledge graph in advance through big data collection, and customizes an entity extraction model based on the feature extraction component of a large language model, and the large language model automatically generates and processes the model training data set of the entity extraction model according to the knowledge graph, and trains the entity extraction model based on the generated data set; and in each question-answering task processing process after the model training is completed, the entity extraction model first extracts entity triples from the question text, and then searches the knowledge graph according to the entity triples extracted at that time to obtain the corresponding knowledge text, and then inputs the knowledge text obtained at that time as reference / prompt information together with the question text into the large language model for corresponding answer text generation processing. When processing a question-answering task, the embodiment of the present invention first obtains knowledge information related to the correct answer through knowledge graph retrieval, and then uses the obtained knowledge information to prompt the large language model to generate the corresponding answer text. The embodiment of the present invention can reduce the error rate of the question-answering task and improve the processing performance of the question-answering task. In addition, the embodiment of the present invention does not perform large-scale training on the large language model, but only performs local training on the customized small model. It does not construct a training data set through manual data collection, but only uses the text generation capability of the large model to automatically construct the training data set. The embodiment of the present invention not only shortens the improvement cycle and improves the improvement efficiency, but also greatly reduces the improvement cost.
[0181] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0182] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for processing question-answering tasks in combination with knowledge graphs, characterized in that: The method comprises: Constructing the first knowledge graph in advance through big data collection; A type of large language model that has been pre-trained and fine-tuned is used as the corresponding first large language model; a processing model for entity triple extraction is customized based on the feature extraction component of the first large language model and recorded as the corresponding entity extraction model; the first large language model automatically generates a model training data set of the entity extraction model according to the first knowledge graph to obtain a corresponding first data set; and the entity extraction model is trained based on the first data set; After the model training is completed, the question text received from the user is recorded as the corresponding current question text; the entity extraction model performs entity triple extraction processing on the current question text to obtain the corresponding current entity triplet; and performs knowledge retrieval processing based on the current entity triplet and the first knowledge graph to obtain the corresponding current knowledge text; and the current question text and the current knowledge text are brought into the preset question and answer instruction template to perform question and answer instruction text splicing processing to obtain the corresponding current question and answer instruction text; and the current question and answer instruction text is input into the first language model to perform answer text generation processing to obtain the corresponding current answer text to be fed back to the user.
2. The method for processing question-answering tasks in combination with knowledge graph according to claim 1, characterized in that: The first knowledge graph consists of a first node set and a first edge set; the first node set includes a plurality of first nodes; the first edge set includes a plurality of first edges; Each of the first nodes corresponds to an entity; the node attributes of the first node include a node identifier, a node update time, a node entity concept type, a node entity role, and a node entity attribute set; the node identifier is a unique identifier of the current node; the node update time is the latest addition or update time of the current node; the node entity concept type is a class of preset entity concept types; the node entity role is a specific role parameter of the entity corresponding to the current node; Each of the first edges is a directed edge; the starting node of each of the first edges is recorded as a parent entity node, and the ending node is recorded as a child entity node; the edge attributes of the first edge include edge identifier, edge update time, parent entity node identifier, child entity node identifier, and parent-child entity relationship type; the edge identifier is a unique identifier of the current edge; the edge update time is the latest addition or update time of the current edge; the parent entity node identifier is the node identifier of the parent entity node corresponding to the current edge; the child entity node identifier is the node identifier of the child entity node corresponding to the current edge; the parent-child entity relationship type is a preset entity relationship type; The first data set is composed of a plurality of first data records; the first data record includes a first training text and a first label entity triple; when the first label entity triple is not empty, it is composed of a first label parent entity attribute, a first label child entity attribute and a first label parent-child relationship type; the first label parent entity attribute includes a first label parent entity role and a first label parent entity type; the first label child entity attribute includes a first label child entity role and a first label child entity type; the first label parent entity type and the first label child entity type each correspond to a class of preset entity concept types, and the first parent-child relationship type corresponds to a class of preset entity relationship types; The question and answer instruction template is a formatted text configuration template; the question and answer instruction template is used to use the current question text and the current knowledge text as the corresponding original question text and prompt information text; And through a preset narrative text, the first language model is informed to use the prompt information text as reference information to generate the corresponding answer text for the question given in the original question text and output the generated answer text.
3. The method for processing question-answering tasks in combination with knowledge graph according to claim 1, characterized in that: The first language model includes at least a GPT series model and a BERT series model; The first language model performs corresponding natural language text generation processing based on the natural language understanding of the first instruction text input to the model and outputs the corresponding first generated text; The language model input end of the first large language model is used to receive the first instruction text, and the language model output end is used to output the corresponding first generated text; The internal model components of the first large language model at least include a first word segmentation module, a first word embedding encoding module, a first feature extraction module and a first text generator module; The input end of the first word segmentation module is connected to the input end of the language model, and the output end is connected to the input end of the first word embedding encoding module; the output end of the first word embedding encoding module is connected to the input end of the first feature extraction module; the output end of the first feature extraction module is connected to the input end of the first text generator module; the output end of the first text generator module is connected to the output end of the language model; The first word segmentation module is used to perform word segmentation processing on the first instruction text to generate a corresponding first word segmentation sequence and send it to the first word embedding encoding module; the first word segmentation sequence is formed by sequentially sorting a plurality of first word segmentations; The first word embedding encoding module is used to perform word embedding encoding processing on each of the first word segmentations in the first word segmentation sequence to obtain a corresponding first word segmentation encoding tensor and send it to the first feature extraction module; the first word segmentation encoding tensor is formed by sequentially sorting a plurality of first word segmentation encoding vectors, and the first word segmentation encoding vectors correspond to the first word segmentations one by one; The first feature extraction module is implemented based on the Encoder or Decoder component structure of the Transformer model; the first feature extraction module is used to perform deep learning on the associated features of each word segmentation encoding vector and other word segmentation encoding vectors in the first word segmentation encoding tensor to obtain a corresponding first feature tensor and send it to the first text generator module; the first feature tensor is composed of multiple first feature vectors, and the first feature vector corresponds to the first word segmentation one by one; The first text generator module is implemented based on a type of text generator model structure; it is used to perform feature decoding and text generation processing according to the first feature tensor to obtain the corresponding first generated text and output it.
4. The method for processing question-answering tasks in combination with knowledge graph according to claim 1, characterized in that: The entity extraction model is used to perform entity triple extraction processing on the first text to be extracted input by the model and output the corresponding first entity triple; when the first entity triple is not empty, it is composed of a first parent entity attribute, a first child entity attribute and a first parent-child relationship type; the first parent entity attribute includes a first parent entity role and a first parent entity type; the first child entity attribute includes a first child entity role and a first child entity type; the first parent entity type and the first child entity type each correspond to a class of preset entity concept types, and the first parent-child relationship type corresponds to a class of preset entity relationship types; The extraction model input end of the entity extraction model is used to receive the first text to be extracted, and the extraction model output end is used to output the corresponding first entity triple; The internal model component of the entity extraction model is composed of the first word segmentation module, the first word embedding encoding module and the first feature extraction module of the first large language model, and the first fully connected network, the first softmax layer, the first parent-child entity recognition module, the first word segmentation relevance score calculation module, the first relationship feature vector recognition module, the second fully connected network, the second softmax layer, the first relationship type recognition module and the first triple fusion module. The connection relationship of the internal model components of the entity extraction model is as follows: the input end of the first word segmentation module is connected to the input end of the extraction model, and the output end is respectively connected to the input end of the first word embedding encoding module and the third input end of the first triple fusion module; the output end of the first word embedding encoding module is connected to the input end of the first feature extraction module; the output end of the first feature extraction module is respectively connected to the input end of the first fully connected network, the second input end of the first word segmentation relevance score calculation module and the second input end of the first relationship feature vector recognition module; the output end of the first fully connected network is connected to the input end of the first softmax layer; the output end of the first softmax layer is connected to the input end of the first parent-child entity recognition module; The output end of a parent-child entity recognition module is respectively connected to the first input end of the first word segmentation relevance score calculation module and the first input end of the first triple fusion module; the output end of the first word segmentation relevance score calculation module is connected to the first input end of the first relationship feature vector recognition module; the output end of the first relationship feature vector recognition module is connected to the input end of the second fully connected network; the output end of the second fully connected network is connected to the input end of the second softmax layer; the output end of the second softmax layer is connected to the input end of the first relationship type recognition module; the output end of the first relationship type recognition module is connected to the second input end of the first triple fusion module; the output end of the first triple fusion module is connected to the output end of the extraction model; The first word segmentation module of the entity extraction model is used to perform word segmentation processing on the first text to be extracted to generate a corresponding second word segmentation sequence S and send it to the first word embedding encoding module and the first triple fusion module; the second word segmentation sequence S consists of multiple second word segmentations s i The index i is sorted in order, 1≤partition index i≤N, and N is the total number of participles in the second participle sequence S; The first word embedding encoding module of the entity extraction model is used to encode each second word s of the second word sequence S i The word embedding encoding process is performed to obtain the corresponding second word segmentation encoding tensor X, which is sent to the first feature extraction module; the second word segmentation encoding tensor X is composed of N second word segmentation encoding vectors x i The second word segmentation encoding vector x i With the second participle s i One-to-one correspondence; the second word segmentation encoding vector x i The vector length of is the preset encoding vector length threshold L hold ; The first feature extraction module of the entity extraction model is used to perform deep learning on the associated features of each word segmentation coding vector in the second word segmentation coding tensor X and other word segmentation coding vectors to obtain the corresponding second feature tensor H and send it to the first fully connected network, the first word segmentation relevance score calculation module and the first relationship feature vector recognition module; the second feature tensor H is composed of N second feature vectors h i The second eigenvector h i With the second participle s i One-to-one correspondence; the second eigenvector h i The length of the vector is L hold ; The first fully connected network of the entity extraction model is implemented based on a fully connected layer or multiple fully connected layers connected in sequence; the first fully connected network is used to calculate each of the second feature vectors h of the second feature tensor H through full connection. i Perform the corresponding concept type feature conversion to obtain the corresponding third feature vector a i ; and by the obtained N third eigenvectors a i The corresponding third feature tensor A is sent to the first softmax layer; the third feature tensor A is composed of N third feature vectors a i The third eigenvector a i With the second participle s i One-to-one correspondence; the third eigenvector a i The vector length is M+1, where M is the total number of preset entity concept types; The first softmax layer of the entity extraction model is implemented based on a softmax function; the first softmax layer is used to extract the third feature vectors a according to the third feature tensor A. i Perform the corresponding entity concept classification prediction process to obtain the corresponding first prediction probability vector pa i ; and the obtained N first prediction probability vectors pa i The first prediction probability tensor PA is composed of N first prediction probability vectors pa and sent to the first parent-child entity recognition module; the first prediction probability tensor PA is composed of N first prediction probability vectors pa i The first prediction probability vector pa i With the second participle s i One-to-one correspondence; each of the first prediction probability vectors pa i It is composed of M+1 first prediction probabilities, the first M first prediction probabilities correspond one-to-one to the preset M types of entity concepts, and the last one of the first prediction probabilities corresponds to a non-entity concept type; The first parent-child entity recognition module of the entity extraction model is used to identify all the first prediction probability vectors pa of the first prediction probability tensor PA i Perform a round of traversal; and in this round of traversal, the first prediction probability vector pa currently traversed i as the corresponding current prediction probability vector; and the first prediction probability with the largest probability value in the current prediction probability vector is taken as the corresponding first maximum probability pa max,i and the first maximum probability pa max,i The corresponding entity concept type or the non-entity concept type is used as the corresponding first type ta i ; and at the end of this round of traversal, all the first type ta that are not the non-entity concept type i According to the first maximum probability pa max,i Arrange the first type sequence in descending order to form a corresponding first type sequence; and count the total number of types of the first type sequence to obtain a corresponding first total number; and identify the first total number; If the first total is greater than or equal to 2, the first type ta ranked first two in the first type sequence i The corresponding word segmentation index i is recorded as the corresponding first and second indexes, and the smaller index value in the first and second indexes is used as the corresponding parent entity index, and the larger index value is used as the corresponding child entity index, and the first type ta corresponding to the parent and child entity indexes is recorded as i as the corresponding parent entity concept type and child entity concept type; if the first total is less than 2, the corresponding parent and child entity indexes and the parent and child entity concept types are set to null; and the obtained parent entity index and the parent entity concept type form the corresponding parent entity recognition data, and the obtained child entity index and the child entity concept type form the corresponding child entity recognition data, and the obtained parent and child entity recognition data are sent to the first word segmentation relevance score calculation module and the first triple fusion module; The first word segmentation relevance score calculation module of the entity extraction model is used to convert the two second feature vectors h corresponding to the parent and child entity indexes of the parent and child entity identification data in the second feature tensor H into i Denote as the corresponding parent entity feature vector and child entity feature vector; and the other N-2 second feature vectors h in the second feature tensor H except the parent and child entity feature vectors i are all recorded as the corresponding other feature vectors; and the vector dot product calculation is performed on each of the other feature vectors and the parent entity feature vector, and the calculation result is used as the corresponding parent entity attention score, and the vector dot product calculation is performed on each of the other feature vectors and the child entity feature vector, and the calculation result is used as the corresponding child entity attention score, and the parent and child entity attention scores corresponding to each of the other feature vectors are summed and the calculation result is used as the corresponding first attention score; And normalize the obtained N-2 first attention scores to obtain corresponding N-2 normalized attention scores; The normalized attention scores corresponding to the parent and child entity feature vectors are set to 0; and the second feature vectors h in the second feature tensor H are i The corresponding normalized attention score is recorded as the corresponding first participle relevance score c i ; and the obtained N first word relevance scores c i The first word segmentation relevance score vector C corresponding to the first relationship feature vector recognition module is sent; the first word segmentation relevance score vector C is composed of N first word segmentation relevance scores c i The first word relevance score c i With the second participle s i One to one correspondence; The first relationship feature vector recognition module of the entity extraction model is used to convert the first segmentation relevance score c having the largest score in the first segmentation relevance score vector C into i The corresponding word segmentation index i is used as the corresponding relational word segmentation index; and the second feature vector h corresponding to the relational word segmentation index in the second feature tensor H is used as the corresponding relational word segmentation index. i Send it as the corresponding relation feature vector R to the second fully connected network; The second fully connected network of the entity extraction model is implemented based on a single fully connected layer or multiple sequentially connected fully connected layers; the second fully connected network is used to convert the relationship feature vector R into a corresponding entity relationship type feature through a fully connected calculation to obtain a corresponding fourth feature vector B and send it to the second softmax layer; the vector length of the fourth feature vector B is Q, and Q is the total number of preset entity relationship types; The second softmax layer of the entity extraction model is implemented based on the softmax function; the second softmax layer is used to perform corresponding entity relationship classification prediction processing according to the fourth feature vector B to obtain the corresponding second prediction probability vector PB and send it to the first relationship type recognition module; the second prediction probability vector PB is composed of Q second prediction probabilities pb j Composition, 1≤indexj≤Q; Q second prediction probabilities pb j One-to-one correspondence with the entity relationship types described in the preset Q class; The first relationship type identification module of the entity extraction model is used to convert the second prediction probability vector PB with the largest probability into the second prediction probability vector PB. j The corresponding entity relationship type is sent to the first triple fusion module as the corresponding parent-child entity relationship type; The first triple fusion module of the entity extraction model is used to identify whether the parent and child entity recognition data are empty; if the parent and child entity recognition data are empty, the corresponding first entity triple is set to be empty; if the parent and child entity recognition data are not empty, the word segmentation index i in the second word segmentation sequence S is respectively matched with the second word segmentation s corresponding to the parent and child entity indexes in the parent and child entity recognition data i Extract them as the corresponding first parent entity role and the first child entity role, and use the parent and child entity concept types in the parent and child entity identification data as the corresponding first parent entity type and the first child entity type, and the first parent entity role and the first parent entity type form the corresponding first parent entity attribute, and the first child entity role and the first child entity type form the corresponding first child entity attribute, and the parent-child entity relationship type is used as the corresponding first parent-child relationship type, and the obtained first parent entity attribute, the first child entity attribute and the first parent-child relationship type form the corresponding first entity triplet; and output the obtained first entity triplet.
5. The method for processing question-answering tasks in combination with knowledge graph according to claim 2, characterized in that: The step of constructing the first knowledge graph in advance by collecting big data specifically includes: The first original corpus set is obtained by collecting text corpus big data through multiple big data collection channels; and all the first original corpus texts obtained are subjected to text noise reduction, deduplication, compliance verification and correctness verification based on manual or other machine model screening methods; and each of the processed first original corpus texts is subjected to sentence processing based on manual or other machine model sentence segmentation methods to obtain one or more corresponding first sentence texts; and each of the first training texts is subjected to corresponding entity triple recognition based on manual or other machine model recognition methods and the recognized entity triples are used as corresponding first recognition triples; and corresponding knowledge graph nodes and edge objects are constructed based on the parent and child entity information and parent-child entity relationships of all the first recognition triples obtained to obtain the corresponding first knowledge graph; wherein the multiple big data collection channels include at least a public structured entity triple database, a public text corpus, a public network text resource, and public technical standards / textbooks / documents / magazines / journals / paper resources in various fields; the first original corpus set includes multiple first original corpus texts.
6. The method for processing question-answering tasks in combination with knowledge graph according to claim 2, characterized in that: The step of automatically generating a model training data set of the entity extraction model according to the first knowledge graph by the first large language model to obtain a corresponding first data set specifically includes: Step 61, taking the first edge of the first knowledge graph as the corresponding current edge; Step 62, extract the node entity concept type and the node entity role of the first node corresponding to the parent entity node identifier of the current edge as the corresponding first label parent entity role and the first label parent entity type to form the corresponding first label parent entity attribute; and extract the node entity concept type and the node entity role of the first node corresponding to the child entity node identifier of the current edge as the corresponding first label child entity role and the first label child entity type to form the corresponding first label child entity attribute; and use the parent-child entity relationship type of the current edge as the corresponding first label parent-child relationship type; and form a corresponding first label entity triple by the first label parent entity attribute, the first label child entity attribute and the first label parent-child relationship type corresponding to the current edge; and bring the first label entity triple into a preset text generation instruction template to perform instruction text splicing to obtain the corresponding current instruction text; and input the current instruction text into the first large language model to perform corresponding creative text generation processing and use the generated text output by the model as the corresponding first training text; and form a corresponding first data record by the first training text corresponding to the current edge and the first label entity triple; The text generation instruction template is a formatted text configuration template; the text generation instruction template is used to take the first tag entity triple as the corresponding current entity triple; and inform the first language model through a preset narrative text to generate and output a creative text based on the current entity triple; Step 63, identify whether the current edge is the last first edge of the first knowledge graph; if not, extract the next first edge of the first knowledge graph as the new current edge and return to step 62; if so, all the first data records obtained constitute the corresponding first data set.
7. The method for processing question-answering tasks in combination with knowledge graph according to claim 2, characterized in that: The training of the entity extraction model based on the first data set specifically includes: Step 71, dividing the first data set into two sub-data sets as a corresponding first training set and a first evaluation set based on a preset first division ratio; Wherein, both the first training set and the first evaluation set are composed of a plurality of the first data records; the ratio of the total number of records in the first training set and the first evaluation set satisfies the first segmentation ratio; Step 72, extracting the first first data record in the first training set as the corresponding current training record; Step 73, inputting the first training text of the current training record into the entity extraction model to perform entity triple extraction processing to obtain a corresponding first predicted entity triple; Wherein, when the first predicted entity triple is not empty, it is composed of a first predicted parent entity attribute, a first predicted child entity attribute and a first predicted parent-child relationship type; the first predicted parent entity attribute includes a first predicted parent entity role and a first predicted parent entity type; the first predicted child entity attribute includes a first predicted child entity role and a first predicted child entity type; Step 74: Substitute the first predicted entity triple and the first label entity triple of the current training record into a preset first model loss function L M ; and the preset first model optimizer moves towards making the first model loss function L M Perform a round of optimization processing on the model parameters of the first and second fully connected networks and the first and second softmax layers of the entity extraction model in the direction of achieving the minimum value; Among them, the first model loss function L M for: L M =L CE (x Op ,x Ot )+L CE (x Sp ,x St )+L CE (x Rp ,x Rt )+L cosine (x Onp ,x Ont )+L cosine (x Snp ,x Snt ); L CE () is the cross entropy loss function, L cosine () is the cosine similarity loss function; x Op is the one-hot encoding vector of the entity concept type corresponding to the first predicted parent entity type of the first predicted entity triple; Sp is the one-hot encoding vector of the entity concept type corresponding to the first predicted sub-entity type of the first predicted entity triple; Rp is the one-hot encoding vector of the entity relationship type corresponding to the first predicted parent-child relationship type of the first predicted entity triple; Onp is the N-gram encoding vector corresponding to the first predicted parent entity role of the first predicted entity triple; Snp is the N-gram encoding vector corresponding to the first predicted sub-entity role of the first predicted entity triple; Ot is the one-hot encoding vector of the entity concept type corresponding to the first label parent entity type of the first label entity triple; St is the one-hot encoding vector of the entity concept type corresponding to the first label sub-entity type of the first label entity triple; Rt is the entity relationship type one-hot encoding vector corresponding to the first label parent-child relationship type of the first label entity triple; x Ont is the N-gram encoding vector corresponding to the first label parent entity role of the first label entity triple; Snt The N-gram encoding vector corresponding to the first label sub-entity role of the first label entity triple; The first model optimizer includes at least an SGD optimizer and an ADAM optimizer; Step 75, identifying whether the current training record is the last first data record in the first training set; if so, going to step 76; if not, extracting the next first data record in the first training set as the new current training record and returning to step 73; Step 76, perform a round of traversal on all the first data records of the first evaluation set; and in this round of traversal, use the first data record currently traversed as the corresponding current evaluation record; and input the first training text of the current evaluation record into the entity extraction model to perform entity triple extraction processing to obtain the corresponding second predicted entity triple; and form a corresponding first prediction-label pair from the second predicted entity triple and the first label entity triple of the current training record; and at the end of this round of traversal, bring all the obtained first prediction-label pairs into the preset first model evaluation function F A Performing calculation to obtain a corresponding first evaluation value; Among them, the first model evaluation function F A for: K is the total number of the first prediction-label pairs, 1≤indexk≤K; f e () is MAE error function or MSE error function; x Op,k is the one-hot encoding vector of the entity concept type corresponding to the first predicted parent entity type of the kth first prediction-label pair; Sp,k is the one-hot encoding vector of the entity concept type corresponding to the first predicted sub-entity type of the kth first prediction-label pair; Rp,k is the one-hot encoding vector of the entity relationship type corresponding to the first predicted parent-child relationship type of the kth first prediction-label pair; Onp,k is the N-gram encoding vector corresponding to the first predicted parent entity role of the kth first prediction-label pair; Snp,k is the N-gram encoding vector corresponding to the first predicted sub-entity role of the kth first prediction-label pair; x Ot,k is the one-hot encoding vector of the entity concept type corresponding to the first label parent entity type of the kth first prediction-label pair; St,k is the one-hot encoding vector of the entity concept type corresponding to the first label sub-entity type of the kth first prediction-label pair; Rt,k is the one-hot encoding vector of the entity relationship type corresponding to the first label parent-child relationship type of the kth first prediction-label pair; Ont,k is the N-gram encoding vector corresponding to the first label parent entity role of the kth first prediction-label pair; x Snt,k is the N-gram encoding vector corresponding to the first label sub-entity role of the kth first prediction-label pair; Step 77, identifying whether the first evaluation value satisfies a preset first evaluation value range; if not, returning to step 72 to continue training; if satisfied, stopping training and confirming that the entity extraction model training is completed.
8. The method for processing question-answering tasks in combination with knowledge graph according to claim 2, characterized in that: The step of performing knowledge retrieval processing according to the current entity triple and the first knowledge graph to obtain the corresponding current knowledge text specifically includes: Extracting the corresponding current parent entity role, current parent entity type, current child entity role, current child entity type and current parent-child relationship type from the current entity triplet; and taking the first edge in the first knowledge graph, in which the node entity concept type and the node entity role of the first node corresponding to the parent entity node identifier respectively match the current parent entity type and the current parent entity role, and the node entity concept type and the node entity role of the first node corresponding to the child entity node identifier respectively match the current child entity type and the current child entity role, and the parent-child entity relationship type matches the current parent-child relationship type as the corresponding first retrieval edge; And identify whether the number of the first search edges is unique; if the number of the first search edges is unique, extract the node entity roles of the parent and child entity nodes corresponding to the current first search edge to form the corresponding first knowledge text; if the number of the first search edges is not unique, extract the node entity roles of the parent and child entity nodes corresponding to the first search edge whose edge update time is closest to the current time to form the corresponding first knowledge text; And identify the preset knowledge verification mode; if the knowledge verification mode is a mode that does not require verification, output the first knowledge text as the corresponding current knowledge text; if the knowledge verification mode is a mode that requires verification, verify the correctness of the first knowledge text based on the preset knowledge verification interface to obtain the corresponding first verification result, and when the first verification result is correct, output the first knowledge text as the corresponding current knowledge text; the knowledge verification mode includes a mode that does not require verification and a mode that requires verification; the first verification result includes correct and incorrect.
9. A device for executing the method for processing question-answering tasks in combination with a knowledge graph as described in any one of claims 1 to 8, characterized in that: The device comprises: a knowledge graph preparation module, a model building and training module and a question-answering task processing module; The knowledge graph preparation module is used to construct a first knowledge graph in advance through big data collection; The model building and training module is used to use a type of large language model that has been pre-trained and fine-tuned as the corresponding first large language model; and customize a processing model for entity triple extraction based on the feature extraction component of the first large language model as the corresponding entity extraction model; and the first large language model automatically generates a model training data set of the entity extraction model according to the first knowledge graph to obtain a corresponding first data set; and train the entity extraction model based on the first data set; The question-and-answer task processing module is used to, after the model training is completed, receive the question text input by the user and record it as the corresponding current question text; and the entity extraction model performs entity triple extraction processing on the current question text to obtain the corresponding current entity triplet; and performs knowledge retrieval processing based on the current entity triplet and the first knowledge graph to obtain the corresponding current knowledge text; and brings the current question text and the current knowledge text into a preset question-and-answer instruction template to perform question-and-answer instruction text splicing processing to obtain the corresponding current question-and-answer instruction text; and inputs the current question-and-answer instruction text into the first large language model to perform answer text generation processing to obtain the corresponding current answer text to feedback to the user.
10. An electronic device, characterized in that: include: memory, processors, and transceivers; The processor is used to couple with the memory, read and execute instructions in the memory, so as to implement the method according to any one of claims 1 to 8; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a computer, the computer is enabled to execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Knowledge graph generation type question answering method and system based on large language model
CN117033608A
Physical examination report iconography examination auxiliary interpretation method and device
CN118170892A
Intelligent manufacturing capability diagnosis method and device based on large language model and knowledge graph
CN118410175A
Cited By
Knowledge editing method and device for autoregression large language model
CN120218023A
Processing method and device for updating model knowledge by optimizing MLP weight
CN120218209A
A processing method and device for optimizing MLP weight update model knowledge
CN120218209B
Federal learning system of medical big language model
CN120409627A
A federated learning system of a medical large language model
CN120409627B