Question and answer method and device, computer equipment and storage medium
By extracting features from questions and knowledge graphs from a large language model and applying attention processing, the problem of noisy data interference is solved, thus improving the accuracy of question-answering answers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2026-03-31
AI Technical Summary
Large language models are easily affected by noisy data in knowledge graphs when dealing with complex question-answering tasks, which leads to a decrease in the accuracy of answers.
By acquiring question features and knowledge features from the knowledge graph, attention processing is performed to extract key features and remove noise interference, and the answer is obtained using a large language model.
It improves the accuracy of question-and-answer answers and avoids situations where large language models are misled by noisy features.
Smart Images

Figure CN121765068A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and in particular to a question-and-answer method, apparatus, computer device, and storage medium. Background Technology
[0002] Large Language Model (LLM) is an artificial intelligence technique that can automatically learn language patterns and generate sentences and paragraphs in natural language processing. Currently, LLMs are widely used in various natural language processing fields.
[0003] Because LLMs are prone to using false or outdated knowledge when handling complex question-answering tasks, resulting in incorrect answers, KGQA (Knowledge Graph Question Answering) has emerged. KGQA refers to the task of answering natural language questions using knowledge graphs. After obtaining the question to be answered, relevant knowledge data is retrieved from the knowledge graph. Based on the retrieved knowledge data, the LLM is assisted in predicting the answer, thereby obtaining the answer corresponding to the question.
[0004] However, the above approach is prone to introducing noisy data that is irrelevant to the question into the knowledge graph, which can mislead the LLM and thus reduce the accuracy of the answer. Summary of the Invention
[0005] This application provides a question-answering method, apparatus, computer device, and storage medium that removes interference from noise features in knowledge features, avoiding the situation where large language models are misled by noise features and improving the accuracy of answers. The technical solution is as follows:
[0006] On the one hand, a question-and-answer method is provided, the method comprising:
[0007] Obtain the problem and its corresponding problem characteristics;
[0008] Based on the question, a knowledge graph is retrieved to obtain knowledge data related to the question. The knowledge data includes at least one data type among entity data, relation data, and subgraph data.
[0009] Obtain the knowledge features corresponding to the knowledge data, wherein the knowledge features include at least one feature type among entity features, relation features, and subgraph features;
[0010] Attention processing is applied to the knowledge features to obtain attention features;
[0011] Based on the question features and the attention features, the answer to the question is obtained through a large language model.
[0012] On the other hand, a question-and-answer device is provided, the device comprising:
[0013] The problem acquisition module is used to acquire problems and their corresponding problem characteristics;
[0014] The retrieval module is used to retrieve a knowledge graph based on the question to obtain knowledge data related to the question. The knowledge data includes at least one data type among entity data, relation data, and subgraph data.
[0015] The feature acquisition module is used to acquire the knowledge features corresponding to the knowledge data, wherein the knowledge features include at least one feature type among entity features, relation features, and subgraph features;
[0016] An attention processing module is used to perform attention processing on the knowledge features to obtain attention features;
[0017] The answer acquisition module is used to obtain the answer corresponding to the question based on the question features and the attention features through a large language model.
[0018] In one possible implementation, the feature acquisition module includes:
[0019] The feature acquisition unit is used to acquire the knowledge features corresponding to each of the multiple text segments in the knowledge data belonging to the data type for any data type.
[0020] An average feature determination unit is used to determine the average feature of the knowledge features corresponding to each of the multiple text segments.
[0021] The feature projection unit is used to project the average features to obtain the knowledge features corresponding to the knowledge data.
[0022] In one possible implementation, the attention processing module is used for at least one of the following:
[0023] The entity features are subjected to self-attention processing to obtain entity attention features;
[0024] The relation features are subjected to self-attention processing to obtain relation attention features;
[0025] Cross-attention processing is performed on the entity features and the subgraph features to obtain a first cross-attention feature. Cross-attention processing is performed on the relation features and the subgraph features to obtain a second cross-attention feature. The first cross-attention feature and the second cross-attention feature are combined to obtain the subgraph attention feature.
[0026] In one possible implementation, the answer acquisition module includes:
[0027] The logical form acquisition unit is used to acquire the logical form corresponding to the problem based on the problem features and the attention features through a large language model.
[0028] The answer retrieval unit is used to retrieve the knowledge graph based on the logical form to obtain the answer corresponding to the question.
[0029] In one possible implementation, the logical form acquisition unit is used to combine the problem features and the attention features to obtain a first combined feature; input the first combined feature into the large language model, and obtain the logical form corresponding to the problem through the large language model.
[0030] In one possible implementation, the logical form acquisition unit is used to acquire the correlation between the question feature and the attention feature; based on the correlation, the attention feature is weighted to obtain a weighted attention feature; the question feature and the weighted attention feature are combined to obtain a second combined feature; the second combined feature is input into the large language model, and the logical form corresponding to the question is acquired through the large language model.
[0031] In one possible implementation, the logical form acquisition unit is used for at least one of the following:
[0032] The attention features include entity attention features. The correlation features between the question features and the entity attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance.
[0033] The attention features include relational attention features. The correlation features between the question features and the relational attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the relational relevance.
[0034] The attention features include subgraph attention features. The correlation features between the question features and the subgraph attention features are obtained. The correlation features include the correlation sub-features corresponding to multiple text segments in the question. The average features of the correlation sub-features corresponding to the multiple text segments are normalized to obtain the subgraph correlation.
[0035] In one possible implementation, the logical form acquisition unit is used for at least one of the following:
[0036] The entity attention features and the entity relevance are multiplied element-wise to obtain the weighted entity attention features;
[0037] The element-wise product of the relation attention features and the relation relevance is used to obtain the weighted relation attention features;
[0038] The weighted subgraph attention features are obtained by element-wise multiplying the subgraph attention features and the subgraph relevance.
[0039] In one possible implementation, the logical form acquisition unit is used to concatenate the initialization label feature, the problem feature, and the weighted attention feature to obtain the second combined feature.
[0040] In one possible implementation, the method is performed based on a question-answering model, which includes a feature extraction model and the large language model, wherein the feature extraction model includes an embedding layer and an attention layer;
[0041] The embedding layer is used to obtain the problem features corresponding to the problem and the knowledge features corresponding to the knowledge data.
[0042] The attention layer is used to perform attention processing on the knowledge features to obtain the attention features;
[0043] The large language model is used to obtain the logical form corresponding to the question based on the question features and the attention features;
[0044] The attention layer includes at least one of a first self-attention layer, a second self-attention layer, and a cross-attention layer;
[0045] The first attention layer is used to perform self-attention processing on the entity features to obtain entity attention features;
[0046] The second attention layer is used to perform self-attention processing on the relation features to obtain relation attention features;
[0047] The cross-attention layer is used to perform cross-attention processing on the entity features and the subgraph features to obtain a first cross-attention feature, and to perform cross-attention processing on the relation features and the subgraph features to obtain a second cross-attention feature. The first cross-attention feature and the second cross-attention feature are combined to obtain the subgraph attention feature.
[0048] In one possible implementation, the question-answering model further includes a relevance-gated model, which comprises a Siamese network and an output layer;
[0049] The Siamese network is used to obtain the correlation between the problem features and the attention features;
[0050] The output layer is used to perform weighted processing on the attention features based on the relevance to obtain weighted attention features;
[0051] The twin network includes at least one of a first twin network, a second twin network, and a third twin network;
[0052] The first Siamese network is used to obtain the correlation features between the question features and the entity attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance.
[0053] The second Siamese network is used to obtain the correlation features between the question features and the relational attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the relational relevance.
[0054] The third Siamese network is used to obtain the correlation features between the problem features and the subgraph attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the problem. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the subgraph correlation.
[0055] In one possible implementation, the device further includes:
[0056] The model training module is used to acquire sample data, which includes sample questions, sample knowledge data related to the sample questions, and sample logical forms corresponding to the sample questions; acquire an initial question model; and, with the already trained model parameters in the large language model frozen, train the untrained model parameters in the question answering model based on the sample data to obtain the trained question answering model.
[0057] In one possible implementation, the retrieval module includes:
[0058] The first retrieval unit is used to retrieve related entities of the entity in the knowledge graph based on the entity in the question; and to obtain entity data of the related entities from the knowledge graph.
[0059] In one possible implementation, the retrieval module includes:
[0060] The second retrieval unit is used to replace entities in the question with hidden tags to obtain the question after hiding the entities; based on the question after hiding the entities, it retrieves relationship data matching the question after hiding the entities from the knowledge graph.
[0061] In one possible implementation, the retrieval module includes:
[0062] The third retrieval unit is used to linearize each triple in the knowledge graph to obtain linearized text. The triple includes a head entity, a relation, and a tail entity. The linearized text is text that includes the head entity, the relation, and the tail entity. Based on at least one linearized text, at least one set of text data is created, with the same head entity included in the same set of text data. From the at least one set of text data, target text data that meets the relevance condition of the question is retrieved. Based on the target text data, the subgraph data is obtained.
[0063] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor to perform the operations performed by the question-and-answer method as described above.
[0064] On the other hand, a computer-readable storage medium is provided that stores at least one computer program, which is loaded and executed by a processor to perform the operations performed by the question-and-answer method as described above.
[0065] On the other hand, a computer program product is provided, including a computer program loaded and executed by a processor to perform the operations performed by the question-and-answer method as described above.
[0066] This application provides a question-answering scheme. After retrieving knowledge graphs based on questions and obtaining knowledge data related to the questions, knowledge features corresponding to the knowledge data are obtained, and attention processing is performed on the knowledge features to obtain attention features. This allows for the extraction of key features from the knowledge features and the removal of interference from noise features. In this way, when obtaining answers based on the question features and attention features corresponding to the questions, the large language model can be prevented from being misled by noise features, thus improving the accuracy of the answers. Attached Figure Description
[0067] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0068] Figure 1 This is a schematic diagram of an implementation environment provided in an embodiment of this application;
[0069] Figure 2 This is a flowchart of a question-and-answer method provided in an embodiment of this application;
[0070] Figure 3 This is a flowchart of another question-and-answer method provided in the embodiments of this application;
[0071] Figure 4 This is a schematic diagram of the structure of a question-answering model provided in an embodiment of this application;
[0072] Figure 5 This is a flowchart of another question-and-answer method provided in the embodiments of this application;
[0073] Figure 6 This is a schematic diagram of another question-answering model provided in an embodiment of this application;
[0074] Figure 7 This is a flowchart of another question-and-answer method provided in the embodiments of this application;
[0075] Figure 8 This is a flowchart of a medical question-and-answer method provided in an embodiment of this application;
[0076] Figure 9 This is a schematic diagram of a medical question-and-answer interface provided in an embodiment of this application;
[0077] Figure 10 This is a schematic diagram of the structure of a question-and-answer device provided in an embodiment of this application;
[0078] Figure 11 This is a schematic diagram of another question-and-answer device provided in an embodiment of this application;
[0079] Figure 12 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application;
[0080] Figure 13 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation
[0081] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0082] It is understood that the terms "first," "second," etc., used in this application may be used to describe various concepts herein, but unless otherwise stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of this application, first data may be referred to as second data, and similarly, second data may be referred to as first data.
[0083] "At least two" means two or more. For example, "at least two data" can be any integer greater than or equal to two data, such as two data or three data. "Each" refers to each of the "at least two" data. For example, "each data" refers to each of the "at least two" data. If the "at least two" data consists of three data, then "each data" refers to each of the three data.
[0084] It should be noted that the information (including but not limited to user equipment information, user personal information, etc.), data (including but not limited to data used for analysis, data stored, data displayed, etc.) and signals (including but not limited to signals transmitted between user terminals and other devices) involved in this application have all been fully authorized by the user or relevant parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0085] First, the concepts involved in the embodiments of this application are explained as follows:
[0086] Large Language Models (LLMs) are an artificial intelligence technique that automatically learns language patterns and generates natural language sentences and paragraphs in the field of natural language processing. LLMs utilize unsupervised or semi-supervised learning on massive corpora, employing deep learning techniques to process and learn by encoding each word, phrase, and sentence as a numerical variable, and then training and optimizing the model based on the existing corpus. Currently, LLMs have been applied to various natural language processing problems.
[0087] Knowledge Graph Question Answering (KGQA) refers to the task of using knowledge graphs to answer natural language questions. A knowledge graph is a graphical structure used to describe the relationships between entities, relations, and attributes, typically used to store and organize structured knowledge. In KGQA, the system needs to understand the natural language question, find the relevant entities, relations, and attributes in the knowledge graph, and then generate an executable query to obtain the correct answer. KGQA is an important research direction in natural language processing and artificial intelligence, contributing to applications such as question-answering systems and semantic search engines.
[0088] Figure 1 This is a schematic diagram of an implementation environment provided in an embodiment of this application, such as... Figure 1 As shown, the implementation environment includes a terminal 101 and a question-and-answer system 102.
[0089] Optionally, the terminal 101 can be a smartphone, tablet, laptop, desktop computer, etc., but is not limited to these. Optionally, the question-and-answer system 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal 101 and the question-and-answer system 102 are directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0090] Terminal 101 has a question-and-answer client 111 installed and running. Question-and-answer system 102 is used to provide backend services for question-and-answer client 111, including functions such as generating answers to questions and storing dialogue data. This application embodiment does not limit the functions of question-and-answer system 102.
[0091] Those skilled in the art will understand that the number of terminals described above can be more or less. For example, there may be only one terminal, or there may be six, eight, or more terminals. This application does not limit the number of terminals or the type of device.
[0092] Optionally, the question-answering system 102 undertakes the main computing work, and the terminal 101 undertakes the secondary computing work; or, the question-answering system 102 undertakes the secondary computing work, and the terminal 101 undertakes the main computing work; or, the question-answering system 102 and the terminal 101 adopt a distributed computing architecture for collaborative computing.
[0093] In this embodiment, the user inputs a question in terminal 101, which then sends the question to question-answering system 102. Based on the question and knowledge graph, and through a large language model, question-answering system 102 determines the answer corresponding to the question and sends the answer to terminal 101. Terminal 101 then outputs the answer for the user to view.
[0094] It should be noted that the above implementation environment is only an example, and the method provided in this application embodiment can also be executed in other implementation environments. This application embodiment does not limit this.
[0095] Figure 2 This is a flowchart illustrating a question-and-answer method provided in an embodiment of this application, which is executed by a question-and-answer system. See also... Figure 2 The method includes:
[0096] 201. The question-and-answer system obtains questions and their corresponding question characteristics.
[0097] The question can be entered by the user on the terminal and then sent to the question-and-answer system, or it can be any question determined by the question-and-answer system; this application embodiment does not limit this. Furthermore, the question type varies depending on the scenario. For example, in a medical question-and-answer scenario, the question is a medical query, and the corresponding answer is a medical answer; while in a navigation question-and-answer scenario, the question is a transportation query, and the corresponding answer is transportation routes, etc. This application embodiment does not limit the application scenario.
[0098] After obtaining a question, the question-answering system can extract features from the question to obtain the corresponding question features. These features can describe the question in numerical form, and can be vectors or matrices, etc. This application embodiment does not limit this.
[0099] Optionally, the problem system obtains the problem features corresponding to the problem through a feature extraction model, which can be any model with feature extraction capabilities.
[0100] 202. The question-answering system retrieves knowledge graphs based on questions to obtain knowledge data related to questions. The knowledge data includes at least one data type among entity data, relation data, and subgraph data.
[0101] Knowledge graphs include knowledge data, which can serve as the corpus for question-answering systems, helping them expand their knowledge base and thus improve the accuracy of answers. A knowledge graph is a collection of factual knowledge structured in the form of triples. It includes at least two entities and at least one relationship. For example, a knowledge graph contains multiple nodes and edges connecting them. Each node represents an entity, and each edge represents the relationship between the entities corresponding to the two connected nodes.
[0102] Optionally, the knowledge graph can include knowledge data from different domains in different scenarios. For example, in a medical question-answering scenario, the knowledge graph is a medical knowledge graph, including knowledge data from the medical field; in a navigation question-answering scenario, the knowledge graph is a transportation knowledge graph, including knowledge data from the transportation field. Alternatively, the knowledge graph can include knowledge data from multiple domains to ensure that the question-answering system can answer questions from multiple domains, thus achieving the versatility of the question-answering system.
[0103] Question answering systems retrieve knowledge graphs based on questions to obtain knowledge data related to the questions, while no longer considering knowledge data unrelated to the questions. This can effectively reduce the amount of knowledge data, save computation, and avoid interference from irrelevant knowledge data.
[0104] Knowledge data can include at least one of the following data types: entity data, relational data, and subgraph data. For example, entity data refers to the entity data corresponding to the entity related to the problem. The entity related to the problem can be the same as or similar to the entities included in the problem, and the entity data is used to describe the entity. Relational data can include one or more relations related to the problem, such as "A includes B" or "B belongs to C". Subgraph data includes nodes corresponding to any one or more entities, as well as neighboring nodes connected to that node via one or more edges.
[0105] 203. The question-answering system obtains knowledge features corresponding to knowledge data. Knowledge features include at least one of the following feature types: entity features, relation features, and subgraph features.
[0106] Since knowledge data includes at least one data type among entity data, relation data, and subgraph data, and the acquired knowledge features match the knowledge data, the knowledge features include at least one feature type among entity features, relation features, and subgraph features.
[0107] Optionally, if the knowledge data includes entity data, the question-answering system obtains the entity features corresponding to the entity data. If the knowledge data includes relational data, the question-answering system obtains the relational features corresponding to the relational data. If the knowledge data includes subgraph data, the question-answering system obtains the subgraph features corresponding to the subgraph data.
[0108] 204. The question-answering system performs attention processing on the knowledge features to obtain attention features.
[0109] Among them, attention processing of knowledge features refers to extracting key features from knowledge features to obtain attention features, thereby enhancing the knowledge features and reducing the interference of noisy features in the knowledge features.
[0110] 205. The question-answering system obtains the answer to the question based on question features and attention features through a large language model.
[0111] Problem features are used to describe the problem, while attention features are used to describe key data in the knowledge data related to the problem. Based on problem features and attention features, the large language model can obtain the answer to the problem.
[0112] Optionally, the backbone network of the large language model can be GPT-4, LLaMA2-7B or LLaMA2-13B, etc., and the embodiments of this application do not limit it.
[0113] This application provides a question-answering method. After retrieving knowledge graphs based on questions and obtaining knowledge data related to the questions, knowledge features corresponding to the knowledge data are obtained, and attention processing is performed on the knowledge features to obtain attention features. This allows for the extraction of key features from the knowledge features and the removal of interference from noise features. In this way, when obtaining answers based on the question features and attention features corresponding to the questions, the large language model can be prevented from being misled by noise features, thus improving the accuracy of the answers.
[0114] The above embodiments are merely a brief description of the question-and-answer method. This application also provides another question-and-answer method, and details the question-and-answer process. Figure 3 This is a flowchart of another question-and-answer method provided in an embodiment of this application, which is executed by a question-and-answer system. See also... Figure 3 The method includes:
[0115] 301. The question-and-answer system obtains questions and their corresponding question characteristics.
[0116] 302. The question-answering system retrieves knowledge graphs based on questions to obtain knowledge data related to questions. The knowledge data includes at least one data type among entity data, relation data, and subgraph data.
[0117] Steps 301-302 are the same as steps 201-202, and the repeated content will not be repeated here.
[0118] Optionally, the knowledge data includes entity data and relation data, or the knowledge data includes entity data and subgraph data, or the knowledge data includes relation data and subgraph data, or the knowledge data includes entity data, relation data, and subgraph data. Furthermore, the number of entity data, relation data, and subgraph data in the knowledge data may be one or more, and this embodiment of the application does not limit this.
[0119] Optionally, the process of retrieving entity data includes: retrieving related entities from the knowledge graph based on the entity in the question, and obtaining entity data of the related entities from the knowledge graph.
[0120] A knowledge graph includes at least two entities, plus entity data for at least two more entities, which describes those entities. A question-answering system can identify one or more entities in a question and retrieve related entities from the knowledge graph for each entity, including entities identical to or synonymous with each entity in the question. By identifying the entity data of related entities as question-related entity data, entity data retrieval is achieved, ensuring the relevance between the entity data and the entities in the question, thus improving retrieval accuracy.
[0121] Optionally, ELQ (an end-to-end question entity linking model) is used to retrieve relevant entities from the database. First, the boundaries of mentioned entities in the question are identified, specifically the first and last characters of each mentioned entity, thus identifying the complete mentioned entity. A mentioned entity refers to an entity that appears in the question. These mentioned entities are then matched with entities in the database to determine their related entities within the database.
[0122] For example, a question encoder determines the text features corresponding to each text segment in the question. Based on the determined text features, mentioned entities in the question are detected. A mentioned entity includes one or more text segments in the question. Disambiguation processing is then performed on the mentioned entities, such as correcting typos and identifying synonyms. Furthermore, based on the number of text segments included in the mentioned entity, the text features corresponding to one text segment in the mentioned entity can be determined as the entity features corresponding to the mentioned entity. Alternatively, the text features corresponding to multiple text segments in the mentioned entity can be determined, and the average feature of these multiple text features can be determined as the entity features corresponding to the mentioned entity. Additionally, an entity encoder determines the entity features corresponding to each entity in the database. The inner product of the entity features corresponding to the mentioned entity and the entity features corresponding to each entity in the database is calculated to obtain the relevance between the mentioned entity and each entity in the database. Based on the obtained relevance, relevant entities in the database can be selected. For example, the k entities with the highest relevance in descending order of relevance are selected as the relevant entities of the mentioned entity, where k is a positive integer.
[0123] Optionally, for entities in the problem that are not linked by ELQ, the corresponding annotation data for that entity is queried from the annotation database and used as entity data related to that entity. The annotation database includes annotation data for one or more knowledge items. For example, the annotation database could be a FACC database (a database with annotations).
[0124] Optionally, the process of retrieving relational data includes: replacing entities in the question with hidden tags to obtain the question after the hidden entities, and retrieving relational data matching the question after the hidden entities from the knowledge graph based on the question after the hidden entities.
[0125] In knowledge graphs, relationships are organized in a hierarchical structure. Directly using questions for similarity retrieval is not very effective. Therefore, hiding entities in the questions can avoid the influence of entities, fully emphasize the role of relationships in the questions, and thus retrieve accurate relationship data, improving the accuracy of relationship data.
[0126] For example, if the hidden marker is "[BLANK]", replacing each entity in the question with "[BLANK]" will give you the question with the hidden entities.
[0127] For example, a feature extraction model is used to obtain the problem features corresponding to the question and the relation features corresponding to each relation in the knowledge graph. The relevance between the problem features and each relation feature is then determined. This feature extraction model can be BERT (Bidirectional Encoder Representations from Transformers) or other types of feature extraction models. The relevance can be the dot product of the problem features and relation features or other types of relevance. Based on the obtained relevance, relations relevant to the question can be selected. For example, the k relations with the highest relevance are selected from the knowledge graph in descending order of relevance to form the relation data relevant to the question, where k is a positive integer.
[0128] For example, by replacing entities in the question with hidden tags to obtain the question after hiding the entities, FAISS (a vector database) can be used to retrieve relational data related to the question after hiding the entities. This can speed up the retrieval process and improve the accuracy of the relational data.
[0129] Optionally, the process of retrieving subgraph data includes: linearizing each triple in the knowledge graph to obtain linearized text. Each triple includes a head entity, a relation, and a tail entity. The linearized text is text including the head entity, relation, and tail entity. Based on at least one linearized text, at least one set of text data is created, where the head entities in the same set of text data are identical. From the at least one set of text data, target text data whose relevance to the question meets the relevant conditions is retrieved. Based on the target text data, subgraph data is obtained. The format of each set of text data can be a document or a list, etc., and this embodiment does not limit this.
[0130] The process involves linearizing each triplet, including combining the head entity, relation, and tail entity within the triplet and adding spaces between the head entity and relation, and between the relation and tail entity, to obtain linearized text. To conserve computational resources, the question-answering system only considers the relations and tail entities connected by the head entities, ignoring other relations or entities connected by the tail entities. Then, the linearized texts of triples with the same head entity are concatenated to form one or more sets of documents, ensuring that each set contains the same head entity. The head entities in different sets can be the same or different. For example, if the maximum length of the text data is n words, for a given head entity, if the number of words in the concatenated linearized text is less than n, only one set of text data needs to be created to store the linearized text corresponding to that head entity. However, if the number of words in the concatenated linearized text is greater than n, multiple sets of text data need to be created to store the linearized text corresponding to that head entity separately.
[0131] By linearizing the triples in the knowledge graph and creating text data, subgraph data related to the question can be retrieved. This enables the retrieval of subgraph data while ensuring that the relevance between the subgraph data and the question meets the relevant conditions, thus improving the accuracy of the subgraph data.
[0132] Optionally, BM25 (Best Matching 25, an algorithm for information retrieval and text mining) is used to determine the relevance between the question and the text data, thereby identifying target text data whose relevance to the question meets the relevant conditions. Then, linearized text within the target text data is identified as subgraph data relevant to the question. Specifically, the question is parsed to generate one or more morphemes, the relevance of each morpheme to each piece of text data is calculated, and the weighted sum of the relevances of each morpheme in the question to the same piece of text data is obtained to determine the relevance between the question and the text data.
[0133] It should be noted that the embodiments of this application can simultaneously retrieve knowledge data of the above three data types. Each data type has different aspects of information, which can complement each other and share commonalities. Therefore, the question-answering system can effectively align the key knowledge data of the three data types.
[0134] 303. For any data type, the question answering system obtains the knowledge features corresponding to each of the multiple text segments in the knowledge data belonging to that data type, determines the average feature of the knowledge features corresponding to each of the multiple text segments, and projects the average feature to obtain the knowledge features corresponding to the knowledge data.
[0135] Projection refers to the process of mapping high-dimensional features to a low-dimensional space through linear transformation. Projecting the average features involves performing a linear transformation on the average features to obtain the knowledge features in the low-dimensional space. The projection process can reduce the dimensionality of the average features and remove redundant information, thereby reducing the complexity of subsequent processing of the knowledge features. Question answering systems can use a projection function to project the average features. This projection function can be a function pre-set by the question answering system or a projection function learned during the training of the question answering model.
[0136] Optionally, the following formula can be used to determine the knowledge features corresponding to the knowledge data:
[0137]
[0138] Where T represents knowledge data, which can be entity data, relational data, or subgraph data; Embeddings() represents the embedding function; and X... e This includes the knowledge features corresponding to each of the multiple text segments in the knowledge data. i represents the sequence number of the text segment, l represents the number of text segments in the knowledge data, and X... e [i] represents the knowledge feature corresponding to the i-th text segment. M() represents the average feature of the knowledge features corresponding to multiple text segments, and X represents the projection function. t This represents the knowledge features corresponding to the knowledge data.
[0139] The text segment can be a word, a phrase, a sentence, etc., and can also be called a token.
[0140] In this embodiment, knowledge data is divided into multiple text segments. After obtaining the knowledge features corresponding to each text segment in the knowledge data, the average feature is calculated. Then, the average feature is projected to obtain the knowledge features corresponding to the knowledge data. This allows for feature extraction at the text segment level, refining the granularity of feature extraction and thus improving the accuracy of knowledge features and question answering.
[0141] Optionally, the question-answering system determines the target number of text segments in each piece of knowledge data, which can be represented by l. If the number of text segments in any piece of knowledge data exceeds the target number, the text segments in the knowledge data can be reduced to make the remaining number of text segments equal to the target number. Conversely, if the number of text segments in any piece of knowledge data is less than the target number, the text segments in the knowledge data can be supplemented to make the number of supplemented text segments equal to the target number. The supplemented text segments can be specific text segments, and the knowledge features corresponding to specific text segments can be specific values such as 0 or 1.
[0142] Optionally, if the data type includes entity type, i.e., knowledge data includes entity data, then step 303 includes: based on multiple text segments in the entity data, obtaining the entity features corresponding to each of the multiple text segments, determining the average feature of the multiple entity features, and projecting the average feature to obtain the entity features corresponding to the entity data.
[0143] Optionally, if the data type includes relational types, i.e., knowledge data includes relational data, then step 303 includes: based on multiple text segments in the relational data, obtaining the relational features corresponding to each of the multiple text segments, determining the average feature of the multiple relational features, and projecting the average feature to obtain the relational features corresponding to the relational data.
[0144] Optionally, if the data type includes subgraph type, that is, if the knowledge data includes subgraph data, then step 303 includes: based on multiple text segments in the subgraph data, obtaining the subgraph features corresponding to each of the multiple text segments, determining the average feature of the multiple subgraph features, and projecting the average feature to obtain the subgraph features corresponding to the subgraph data.
[0145] 304. The question-answering system performs attention processing on the knowledge features corresponding to the knowledge data to obtain attention features.
[0146] Optionally, the knowledge features include entity features, and step 304 includes: performing self-attention processing on the entity features to obtain entity attention features. Performing self-attention processing on entity features can associate different parts of the entity features, establish global dependencies, thereby selecting important features from the entity features and filtering out unimportant features.
[0147] Optionally, the knowledge features include relational features. Step 304 includes: performing self-attention processing on the relational features to obtain relational attention features. Performing self-attention processing on the relational features can associate different parts of the relational features, establish global dependencies, thereby selecting important features from the relational features and filtering out unimportant features.
[0148] Optionally, the knowledge features include entity features, relation features, and subgraph features. Step 304 includes: performing cross-attention processing on entity features and subgraph features to obtain a first cross-attention feature; performing cross-attention processing on relation features and subgraph features to obtain a second cross-attention feature; and combining the first and second cross-attention features to obtain a subgraph attention feature. Cross-attention processing can better understand the relationships between different features and effectively capture the dependencies between them. Therefore, performing cross-attention processing on entity features and subgraph features can align the commonalities between entity data and subgraph data, enhance the knowledge features corresponding to problem-related knowledge data in entity data and subgraph data, and remove interference from irrelevant noise features. Similarly, performing cross-attention processing on relation features and subgraph features can align the commonalities between relation data and subgraph data, enhance the knowledge features corresponding to problem-related knowledge data in relation data and subgraph data, and remove interference from irrelevant noise features.
[0149] It should be noted that the above three optional solutions can be combined in any form, and the embodiments of this application do not limit this.
[0150] In this embodiment, considering that knowledge features include at least one of entity features, relation features, and subgraph features, when performing attention processing on knowledge features, self-attention processing can be applied to entity features to associate different parts of the entity features, establish global dependencies, thereby selecting important features from the entity features and filtering out unimportant features, thus removing interference from entity data irrelevant to the problem. Similarly, self-attention processing can be applied to relation features to associate different parts of the relation features, establish global dependencies, thereby selecting important features from the relation features and filtering out unimportant features, thus removing interference from relation data irrelevant to the problem. Furthermore, cross-attention processing can be applied to entity features and subgraph features, as well as to relation features and subgraph features. The resulting first and second cross-attention features are then combined to obtain subgraph attention features. This allows for alignment of commonalities between entity data and subgraph data, enhancing the knowledge features corresponding to problem-related knowledge data in entity data and subgraph data. Similarly, alignment of commonalities between relation data and subgraph data enhances the knowledge features corresponding to problem-related knowledge data in relation data and subgraph data, thus removing interference from noise features unrelated to the problem.
[0151] 305. The question-answering system obtains the logical form corresponding to the question through a large language model based on question features and attention features.
[0152] Logical form is a logical expression used to retrieve knowledge graphs. The format of logical form can be recognized by the knowledge graph, so retrieving the knowledge graph based on the logical form will yield the answer. For example, for the question "What countries are included in Oceania?", the logical form is "(AND(JOIN base.biblioness.bibs_location.loc_type“Country”)(JOIN(R location.location.contains)Qceania))".
[0153] In this embodiment, the question-answering system determines the logical form of the question based on question features and attention features using a large language model, effectively converting the question into a logical form. Subsequently, the system retrieves the answer from the knowledge graph based on this logical form. Note that the output of the large language model is the logical form, not the answer itself.
[0154] In a first possible implementation, step 305 includes: combining the question features and attention features to obtain a first combined feature; inputting the first combined feature into a large language model; and obtaining the logical form corresponding to the question through the large language model. The combination of the question features and attention features can include any combination method such as concatenation, summation, or averaging, and this embodiment does not limit this method.
[0155] The large language model takes the first combined feature, obtained by combining question features and attention features, as input and the logical form corresponding to the question as output. The large language model can obtain the logical form based on the first combined feature. The first combined feature can comprehensively describe the question features and attention features with high accuracy, which speeds up the processing speed of the large language model and thus improves the processing efficiency of the large language model.
[0156] In the second possible implementation, step 305 includes steps 3051-3053:
[0157] 3051. Obtain the correlation between problem features and attention features.
[0158] Relevance represents the correlation between problem features and attention features. Based on the correlation between problem features and attention features, a soft gating mechanism can be constructed, that is, the relevance is used as the weight of the attention features, and the attention features are weighted. In this way, the knowledge data to be used can be adaptively selected from the attention features through weighting. The weighted attention features represent the features corresponding to the selected knowledge data. Therefore, the interference of noise features that are irrelevant to the problem is removed in the weighted attention features, and the correlation between problem features and attention features is considered. This realizes the adaptive extraction of effective features based on relevance and ensures the accuracy of weighted attention features.
[0159] Optionally, step 3051 includes at least one of the following:
[0160] 1. Attention features include entity attention features. The correlation features between question features and entity attention features are obtained. The correlation features include the correlation sub-features corresponding to multiple text segments in the question. The average features of the correlation sub-features corresponding to multiple text segments are normalized to obtain the entity relevance.
[0161] Among them, entity attention features refer to the features obtained by performing self-attention processing on entity data. Since the question includes multiple text segments, the obtained relevance features include the relevance sub-features corresponding to each of the multiple text segments. By normalizing the average features of the relevance sub-features corresponding to each of the multiple text segments, the entity relevance between the question features and entity attention features can be obtained. Entity relevance can represent the relevance between the question and entity data.
[0162] For example, the problem is characterized as follows Entity attention features are Where Z represents the number of text segments in the problem, e represents the number of dimensions of the features corresponding to a text segment, and t k To represent the quantity of entity data, the product of the entity attention feature and the transpose of the question feature is determined as the relevance feature, i.e. G sim The relevance features are represented by columns, where each column represents a relevance sub-feature corresponding to each text segment in the question. Therefore, normalizing the average feature of each column's relevance sub-feature yields the entity relevance. Alternatively, entity attention features and question features can be mapped to the same feature space, resulting in mapped entity attention features and mapped question features. The product of the mapped entity attention features and the transpose of the mapped question features is then determined as the relevance feature, i.e., q. m =M share (Q e ), x c =Mshare (X c ), M share () denotes the mapping function, G sim The relevance features are represented by each column, which represents the relevance sub-feature corresponding to each text segment in the question. Therefore, the entity relevance can be obtained by normalizing the average feature of the relevance sub-features in each column.
[0163] For example, the entity relevance is obtained by normalizing the average features of the relevance sub-features corresponding to each of the multiple text segments, including: normalizing the average features of the relevance sub-features corresponding to each of the multiple text segments using the following formula:
[0164]
[0165] Among them, G sim [:;i] represents the relevance sub-feature in the i-th column of the relevance features, that is, the relevance sub-feature corresponding to the i-th text segment. Sigmiod() represents the normalization function, and g represents the entity relevance.
[0166] 2. Attention features include relational attention features. The correlation features between the question features and relational attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the relational relevance.
[0167] 3. Attention features include subgraph attention features. The correlation features between the question features and the subgraph attention features are obtained. The correlation features include the correlation sub-features corresponding to multiple text segments in the question. The average features of the correlation sub-features corresponding to multiple text segments are normalized to obtain the subgraph correlation.
[0168] The process of obtaining relation relevance and subgraph relevance is the same as the process of obtaining entity relevance, and will not be repeated here.
[0169] 3052. Based on relevance, the attention features are weighted to obtain weighted attention features.
[0170] Optionally, step 3052 includes at least one of the following:
[0171] 1. Multiply the entity attention features and entity relevance element-wise to obtain the weighted entity attention features.
[0172] Element-wise multiplication refers to multiplying each element in the entity attention feature with the element at the same position in the entity relevance to obtain the product element at each position, and then concatenating the product elements at each position to obtain the weighted entity attention feature.
[0173] For example, the weighted entity attention features are determined using the following formula:
[0174] in, G represents the weighted entity attention feature. e e represents the relevance of entities. c ○ represents entity attention features, and ○ represents element-wise multiplication.
[0175] 2. Multiply the relational attention features and relational relevance element by element to obtain the weighted relational attention features.
[0176] Element-wise multiplication refers to multiplying each element in the relation attention feature with the element at the same position in the relation relevance to obtain the product element at each position, and then concatenating each product element at each position to obtain the weighted relation attention feature.
[0177] For example, the weighted relational attention features are determined using the following formula:
[0178] in, G represents the weighted relational attention feature. r r represents the relevance of the relationship. c ○ indicates relational attention features, and ○ indicates element-wise multiplication.
[0179] 3. Multiply the subgraph attention features and subgraph relevance element by element to obtain the weighted subgraph attention features.
[0180] Element-wise multiplication refers to multiplying each element in the subgraph attention feature with the element at the same position in the subgraph relevance to obtain the product element at each position, and then concatenating each product element at each position to obtain the weighted subgraph attention feature.
[0181] For example, the weighted subgraph attention features are determined using the following formula:
[0182] in, G represents the attention feature of the weighted subgraph. s s represents the relevance of the subgraphs. c ○ represents the attention feature of the subgraph, and ○ represents the element-wise multiplication operation.
[0183] Considering that knowledge data includes at least one data type, attention features can correspondingly include at least one of entity attention features, relation attention features, and subgraph attention features. For each acquired attention feature, multiple relevance sub-features corresponding to each text segment in the knowledge data can be obtained, and then the average feature is calculated and normalized to obtain the relevance score. This refines the granularity of the relevance score, thereby improving its accuracy. Furthermore, element-wise multiplying each attention feature with the corresponding type of relevance score enables a weighted processing of the attention features based on relevance, resulting in accurate weighted attention features. This allows the weighted attention features to adaptively extract effective features from the attention features based on relevance, further improving their accuracy.
[0184] 3053. Combine the problem features and weighted attention features to obtain the second combined features. Input the second combined features into the large language model and obtain the logical form corresponding to the problem through the large language model.
[0185] The combination of problem features and weighted attention features can include any combination such as splicing, summing, or averaging features, and this application does not limit this.
[0186] For example, the initial labeled features, question features, and weighted attention features are concatenated to obtain the second combined feature. Here, the initial labeled features are randomly initialized by the question-answering system. For example, the initial labeled features are p. Weighted attention features include weighted entity attention features Weighted relational attention features And weighted subgraph attention features In the case of the second combination of features, The semicolon indicates a concatenation operation. F represents the logical form, θ, φ1, and φ2 represent the large language model, and φ1, φ2 represent the model parameters of the large language model.
[0187] When performing feature combination, in addition to considering problem features and weighted attention features, we can also consider initial label features. By using the initial label features to adjust the second combination features obtained, we can increase the complexity of the second combination features, thereby improving the accuracy of the obtained logical form.
[0188] This application embodiment can also introduce a relevance gating mechanism, using the relevance between the question features and the attention features as the weight of the attention features, and performing weighted processing on the attention features. This allows for adaptive selection of the knowledge data to be used from the attention features through weighted processing. The weighted attention features represent the features corresponding to the selected knowledge data. Therefore, the weighted attention features not only remove interference from noise features irrelevant to the question but also consider the relevance between the question features and the attention features, achieving adaptive extraction of effective features based on relevance. This ensures the accuracy of the weighted attention features, thereby improving the accuracy of the subsequently obtained logical form. Furthermore, the large language model takes the second combined feature obtained by combining the question features and the weighted attention features as input and the logical form corresponding to the question as output. The large language model can obtain the logical form based on the second combined feature, which can comprehensively describe the question features and the weighted attention features with high accuracy, accelerating the processing speed of the large language model and thus improving its processing efficiency.
[0189] 306. The question-answering system retrieves the answers to questions from the knowledge graph based on logical forms.
[0190] Question-answering systems can directly retrieve information from a knowledge graph based on a defined logical form. However, considering that the defined logical form may contain non-existent entities or relationships—for example, when asking "Where was Rihanna born and raised?", the generated logical form might be "(JOIN(R people.person.place_of_birth)Rihana)"—this form contains the incorrect entity "Rihana," rendering it unexecutable and unable to yield the correct answer by searching the knowledge graph. Therefore, to improve the quality of the logical form, it can be optimized.
[0191] Optionally, optimizing the logical form includes: obtaining the similarity between each entity in the logical form and the entity labels in the entity set, wherein the entity set includes one or more entity labels, and the entity labels in the entity set are correct entity labels. Therefore, based on the determined similarity, entity labels with similarity greater than a preset threshold are added to the entity subset, thereby retaining the entity subset related to the logical form. Then, each entity in the logical form can be replaced with the corresponding entity label in the entity subset to ensure that the entities in the replaced logical form are correct entities.
[0192] Optionally, optimizing the logical form may further include: retrieving the knowledge graph based on the retained entity subset to obtain relationships related to the entity labels in the entity subset, such as relationships connected to the nodes corresponding to the entity labels, or relationships connected to the nodes corresponding to the entity labels and other relationships connected to another node connected to the relationship, thereby obtaining a set of relationships; obtaining the similarity between each relationship in the logical form and each relationship in the set of relationships; and, based on the determined similarity, replacing the corresponding relationships in the logical form with relationships in the set whose similarity is greater than a preset threshold, to ensure that the relationships in the replaced logical form are correct relationships.
[0193] After optimizing the logical form, it can be ensured that the optimized logical form can be better aligned with the knowledge graph. After converting the optimized logical form into SPARQL (a query language), the knowledge graph is retrieved based on the logical form of the converted language, thereby obtaining the answer to the question. The query process can be represented as a = query(convert(F)), where a represents the answer, F represents the optimized logical form, convert(F) represents the logical form after conversion into SPARQL language, and query represents the retrieval of the knowledge graph.
[0194] For example, the question is "Which countries are included in Oceania?", and the logical form is "(AND(JOINbase.biblioness.bibs_location.loc_type“Country”)(JOIN(Rlocation.location.contains)Qceania))", and the corresponding answer is "Australia, Fiji, New Zealand, etc."
[0195] This application provides a question-answering method. After retrieving knowledge graphs based on questions and obtaining knowledge data related to the questions, the method acquires knowledge features corresponding to the knowledge data and performs attention processing on the knowledge features to obtain attention features. This allows for the extraction of key features from the knowledge features and the removal of interference from noise features. In this way, when obtaining the logical form based on the question features and attention features corresponding to the questions, the method avoids the large language model being misled by noise features, improves the accuracy of the logical form, and thus improves the accuracy of the retrieved answers when retrieving knowledge graphs based on the logical form.
[0196] Based on the above embodiments, the question-answering method can also be executed by the question-answering system based on the question-answering model. Figure 4 This is a schematic diagram of the structure of a question-answering model provided in an embodiment of this application. Figure 5 This is a flowchart of another question-answering method provided in an embodiment of this application. This embodiment of the application provides a detailed description of the processing procedure of the question-answering model. See also... Figure 4 and Figure 5 The method includes:
[0197] 501. The question-answering system obtains questions, retrieves knowledge graphs based on the questions, and obtains knowledge data related to the questions. The knowledge data includes at least one data type among entity data, relational data, and subgraph data.
[0198] Step 501 is the same as steps 201-202 and 301-302 above, and will not be repeated here.
[0199] 502. The question-answering system obtains the question features corresponding to the question through the embedding layer, and obtains the knowledge features corresponding to the knowledge data. The knowledge features include at least one feature type among entity features, relation features, and subgraph features.
[0200] The question-answering model includes a feature extraction model and a large language model. The feature extraction model includes an embedding layer and an attention layer. The embedding layer can be an embedding algorithm layer or other network layers used for feature extraction; this embodiment does not limit this. The question-answering system inputs the question into the embedding layer, whereby the embedding layer extracts features from the question to obtain question features. Similarly, knowledge data is input into the embedding layer, where the embedding layer extracts features from the knowledge data to obtain knowledge features. Optionally, when the knowledge data includes knowledge data of different data types, each data type is input into the embedding layer separately, whereby the embedding layer extracts features from the input knowledge data to obtain knowledge features. When the knowledge data includes at least one data type among entity data, relation data, and subgraph data, the knowledge features include at least one feature type among entity features, relation features, and subgraph features.
[0201] 503. The question-answering system performs attention processing on knowledge features through an attention layer to obtain attention features.
[0202] After obtaining the knowledge features, the question-answering system inputs the knowledge features into the attention layer, and the attention layer performs attention processing on the knowledge features to obtain attention features.
[0203] In this embodiment of the application, knowledge data includes at least one of entity data, relation data, and subgraph data. The attention layer includes at least one of a first self-attention layer, a second self-attention layer, and a cross-attention layer. Figure 4 Taking the first self-attention layer, the second self-attention layer, and the cross-attention layer as an example.
[0204] The first attention layer is used to perform self-attention processing on entity features to obtain entity attention features; the second attention layer is used to perform self-attention processing on relation features to obtain relation attention features; the cross attention layer is used to perform cross attention processing on entity features and subgraph features to obtain the first cross attention feature, and to perform cross attention processing on relation features and subgraph features to obtain the second cross attention feature. The first cross attention feature and the second cross attention feature are combined to obtain the subgraph attention feature.
[0205] Optionally, e c E represents entity attention features. t Represents entity data; Self-Attn() represents the self-attention processing performed by the first self-attention layer. r c Representing relational attention features, R t Representing relational data, Self-Attn() indicates the self-attention processing performed by the second self-attention layer; s c This represents the attention features of the subgraph. This represents the first cross-attention feature. S represents the second cross-attention feature. t Represents subgraph data, E t Representing entity data, R t This represents relational data, and Cross-Attn() indicates cross-attention processing. Additionally, 'e' represents the number of dimensions of the features corresponding to a text segment, and 't'... k This indicates the quantity of entity data, relational data, and subgraph data.
[0206] 504. The question-answering system obtains the logical form corresponding to the question based on question features and attention features through a large language model.
[0207] 505. The question-answering system retrieves the answers to questions from the knowledge graph based on logical forms.
[0208] Steps 504-505 are the same as steps 305-306 above, and will not be repeated here.
[0209] This application provides a question-answering model, which includes a feature extraction model and a large language model. After retrieving knowledge graphs based on questions and obtaining knowledge data related to the questions, the embedding layer in the feature extraction model is used to obtain knowledge features corresponding to the knowledge data. Then, the attention layer in the feature extraction model is used to perform attention processing on the knowledge features to obtain attention features. This allows for the extraction of key features from the knowledge features and the removal of interference from noisy features. In this way, when obtaining logical forms through the large language model, the situation where the large language model is misled by noisy features can be avoided, improving the accuracy of the logical forms. As a result, when retrieving knowledge graphs based on logical forms, the accuracy of the retrieved answers can be improved.
[0210] Furthermore, the attention layer can include at least one of a first self-attention layer, a second self-attention layer, and a cross-attention layer. Such a model architecture can achieve self-attention processing of entity data and relation data, and can also perform cross-attention processing of entity data and relation data with subgraph data respectively, thereby removing the interference of entity data and relation data that are irrelevant to the problem. It also aligns the commonalities between entity data and subgraph data, and aligns the commonalities between relation data and subgraph data, thereby enhancing the knowledge features corresponding to the knowledge data that are relevant to the problem, and thus removing the interference of noise features that are irrelevant to the problem.
[0211] In the above Figure 5 Based on the embodiments shown, this application also provides another question-and-answer model. Figure 6 This is a schematic diagram of another question-answering model provided in an embodiment of this application. Figure 7 This is a flowchart of another question-answering method provided in an embodiment of this application. This embodiment of the application provides a detailed description of the processing procedure of the question-answering model. See also... Figure 6 and Figure 7 The method includes:
[0212] 701. The question-answering system obtains questions, retrieves knowledge graphs based on the questions, and obtains knowledge data related to the questions. The knowledge data includes at least one data type among entity data, relational data, and subgraph data.
[0213] 702. The question-answering system obtains the question features corresponding to the question through the embedding layer, and obtains the knowledge features corresponding to the knowledge data. The knowledge features include at least one feature type among entity features, relation features and subgraph features.
[0214] 703. The question-answering system performs attention processing on knowledge features through an attention layer to obtain attention features.
[0215] Steps 701-703 are the same as steps 501-503 above, and will not be repeated here.
[0216] 704. The question-answering system obtains the correlation between question features and attention features through a Siamese network.
[0217] See Figure 6 The question-answering model includes a feature extraction layer and a large language model. The feature extraction model includes an embedding layer and an attention layer. Furthermore, the question-answering model also includes a relevance gating model, which includes a Siamese network and an output layer.
[0218] The question-answering system inputs question features and attention features into a Siamese network to obtain the correlation between the question features and attention features, which is then used to represent the relevance between them. Optionally, the Siamese network includes two mapping networks with shared network parameters. By inputting the question features and attention features into the corresponding mapping networks, mapped question features and mapped attention features can be obtained, thus mapping the question features and attention features to the same feature space. The correlation between the mapped question features and mapped attention features is then obtained.
[0219] Optionally, the twin network includes at least one of a first twin network, a second twin network, and a third twin network.
[0220] The first twin network is used to obtain the correlation features between the question features and the entity attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance.
[0221] For example, q m =M share (Q e ), x c =M share (X c ), M share () represents two mapping networks in the first twin network, G sim The relevance features are represented by each column, which represents the relevance sub-feature corresponding to each text segment in the question. Therefore, the entity relevance can be obtained by normalizing the average feature of the relevance sub-features of multiple columns.
[0222] For example, the entity relevance is obtained by normalizing the average features of the relevance sub-features corresponding to each of the multiple text segments, including: normalizing the average features of the relevance sub-features corresponding to each of the multiple text segments using the following formula:
[0223]
[0224] Among them, G sim [:;i] represents the relevance sub-feature in the i-th column of the relevance features, that is, the relevance sub-feature corresponding to the i-th text segment. Sigmiod() represents the normalization function, and g represents the entity relevance.
[0225] The second Siamese network is used to obtain the relevance features between the question features and the relationship attention features. The relevance features include the relevance sub-features corresponding to each of the multiple text segments in the question. The average features of the relevance sub-features corresponding to each of the multiple text segments are normalized to obtain the relationship relevance.
[0226] The third Siamese network is used to obtain the correlation features between the question features and the subgraph attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the subgraph correlation.
[0227] The process by which the second and third twin networks obtain relational relevance and subgraph relevance is the same as the process by which the first twin network obtains entity relevance, and will not be repeated here.
[0228] 705. The question-answering system uses the output layer to weight the attention features based on relevance, resulting in weighted attention features.
[0229] Step 705 is the same as step 3052 above, and will not be repeated here.
[0230] 706. The question-answering system combines question features and weighted attention features to obtain a second combined feature. The second combined feature is then input into a large language model to obtain the logical form corresponding to the question.
[0231] Step 706 is the same as step 3053 above, and will not be repeated here.
[0232] 707. The question-answering system retrieves the answers to questions from the knowledge graph based on logical forms.
[0233] Step 707 is the same as steps 205 and 306 above, and will not be repeated here.
[0234] This application provides a question-answering model, which includes a feature extraction model, a relevance gating model, and a large language model. After retrieving knowledge graphs based on questions and obtaining knowledge data related to the questions, the embedding layer in the feature extraction model obtains the knowledge features corresponding to the knowledge data. The attention layer in the feature extraction model then performs attention processing on the knowledge features to obtain attention features, thereby extracting key features from the knowledge features and removing interference from noisy features. Furthermore, the Siamese network in the relevance gating model obtains the relevance between the question features and the attention features. The output layer in the relevance gating model then performs weighted processing on the attention features based on the relevance to obtain weighted attention features. This achieves adaptive extraction of effective features based on relevance, ensuring the accuracy of the weighted attention features. Thus, when obtaining logical forms through the large language model, it avoids the large language model being misled by noisy features, improving the accuracy of the logical forms. This, in turn, improves the accuracy of the retrieved answers when retrieving knowledge graphs based on logical forms.
[0235] In the above Figure 5 and Figure 7 Based on the illustrated embodiment, the process of training the question-answering model includes: acquiring sample data, which includes sample questions, sample knowledge data related to the sample questions, and sample logical forms corresponding to the sample questions; acquiring an initial question model; and, with the model parameters already trained in the large language model frozen, training the untrained model parameters in the question-answering model based on the sample data to obtain the trained question-answering model.
[0236] The sample question can be any question, such as one belonging to the target domain of the question-answering model, or a general question applicable to multiple domains; this application does not limit this. The sample knowledge data related to the sample question can be knowledge data related to the sample question obtained by retrieving a knowledge graph based on the sample question. This sample knowledge data can be the knowledge data remaining after removing irrelevant knowledge data from the retrieved knowledge data, or it can be the retrieved knowledge data itself without removing irrelevant knowledge data. The sample logical form can be determined by a technician based on the sample question.
[0237] The initial problem model includes a feature extraction model, a relevance gating model, and a large language model. The large language model is a pre-trained model, meaning all or part of its parameters have been trained, giving it basic capabilities for natural language processing, but it cannot yet accurately perform the question-answering task described in this embodiment. The feature extraction model and the relevance gating model can also be pre-trained models, or they can be untrained models. Then, the trained parameters of the large language model are frozen, allowing the untrained parameters of the question-answering model to be trained based on sample data, resulting in a trained question-answering model.
[0238] For example, a sample question is input into a question-answering model. The logical form corresponding to the sample question is obtained through the feature extraction model, relevance gating model, and large language model in the question-answering model. Based on the obtained logical form and the sample logical form, the loss value is determined. With the model parameters that have been trained in the large language model frozen, the unfrozen model parameters are adjusted based on the loss value. After one or more adjustments, the training is completed and the trained question-answering model is obtained.
[0239] Optionally, the model parameters in the large language model are trained model parameters, while untrained model parameters include model parameters in the feature extraction model, model parameters in the relevance gating model, etc. The model parameters in the large language model may include θ, φ1, and φ2 from step 3053 above.
[0240] Optionally, in step 3053 above, the initial labeled features used to concatenate the question features and weighted attention features are also one of the model parameters of the question answering model. Therefore, these initial labeled features will be trained during the training of the question answering model, thereby improving the generalization ability of the question answering model. After the question answering model is trained, the trained initial labeled features can be used.
[0241] Optionally, after obtaining the pre-trained large language model, the large language model can also be connected to LoRA (Lo w - Rank Adaptation (a lightweight network model) The model parameters in the LoRA model have not been trained. Therefore, the untrained model parameters include the model parameters in the feature extraction model, the model parameters in the relevance gating model, and the model parameters in the LoRA model. During the training of the question answering model, the untrained model parameters mentioned above will be trained while the already trained model parameters in the large language model are frozen.
[0242] This application provides a scheme for training a question-answering model. Based on a pre-trained large language model, the system freezes the trained model parameters in the large language model and trains the untrained model parameters in the question-answering model. This allows the system to train a question-answering model with the ability to generate logical forms, based on the large language model's basic natural language processing capabilities. Furthermore, this accelerates the training speed and improves training efficiency.
[0243] This application provides an adaptive multi-faceted retrieval-enhanced knowledge graph question-answering model framework. It retrieves knowledge data including entity data, relation data, and subgraph data. Instead of directly appending the retrieved knowledge data as context for the question, this model flexibly utilizes the retrieved knowledge data, converting it into knowledge features. The question-answering model comprises two key components: a feature extraction model and a relevance gating model. The feature extraction model maps entity data, relation data, and subgraph data to features for fine-grained adjustments. Furthermore, by applying self-attention and cross-attention processing to multi-faceted knowledge features, it obtains corresponding attention features, aligning commonalities between different types of knowledge data to enhance key features within the retrieved knowledge data and reduce interference from noisy features. For example, if both entity data and subgraph data mention "Oceania," it proves that the entity data and the subgraph data are consistent in conveying the same information. The relevance gating model uses a soft gating mechanism to learn the relevance between the question and multi-faceted knowledge data, determining which information should be used to enhance the output of the large language model. The relevance-gated model introduces a Siamese network with shared parameters to learn the relevance between questions and knowledge data. This relevance serves as a soft gate, adaptively determining which information is more useful for reasoning in a large language model. Through feature extraction and relevance-gated models, it adaptively filters and selects knowledge data from multiple perspectives, achieving more reasonable use of context and avoiding interference from noisy features. Furthermore, it can efficiently train and fine-tune the question-answering model, using retrieved knowledge data to help generate a reasonable logical form for the question, optimize this logical form, and finally query the knowledge graph based on the optimized logical form to obtain the corresponding answer.
[0244] In addition, experiments were conducted on two datasets: WebQSP (Web Questions Semantic Parses Dataset) and CWQ (Complex Web Questions). For each dataset, evaluation metrics for the question-answering model and related technologies provided in this application embodiment were determined, including: F1 (a comprehensive evaluation metric, a weighted average of precision and recall), Hits@1 (an evaluation metric representing the average percentage of triples with a rank less than or equal to 1), and ACC (an evaluation metric representing the ratio of correctly predicted samples to the total number of samples). The evaluation metrics are shown in Table 1 below, where the number before "±" represents the mean, and the number after "±" represents the standard deviation. Comparison shows that the present application embodiment outperforms other related technologies in all evaluation metrics on both datasets. For example, on the WebQSP dataset, compared with related technology 4, the accuracy of the question-answering model provided in this application embodiment is improved by 1.6%. Two additional metrics were used to evaluate the quality of the generated logical form: EM (Extract Match Ratio) and BM (Match after...). Compared to techniques that directly use retrieved knowledge data, the beamsearch ratio (BFR) of the question-answering model provided in this application improves the quality of the logical form generated by the model by 6.6%. This result demonstrates the effectiveness of the question-answering model in improving the reasoning ability of large language models.
[0245] Table 1
[0246]
[0247] In addition, different variations of the question-answering model provided in the embodiments of this application were made, and evaluation metrics for each variation model for the WebQSP dataset were determined. The evaluation metrics are shown in Table 2 below.
[0248] Table 2
[0249]
[0250] Scheme 1 involves removing the Siamese network from the question-answering model provided in this application embodiment and determining the relevance between the question features and attention features as the inner product. Scheme 2 involves removing the feature extraction model from the question-answering model provided in this application embodiment. Scheme 3 involves removing the relevance gating model from the question-answering model provided in this application embodiment. Scheme 4 involves removing both the feature extraction model and the relevance gating model, and only using an MLP (Multilayer Perceptron) network to obtain the knowledge features corresponding to the knowledge data. Scheme 5 involves directly attaching the retrieved knowledge data as context to the question without converting the knowledge data into knowledge features.
[0251] As can be seen from Table 2, when the Siamese network, feature extraction model, or relevance gating model is removed, the performance of most evaluation metrics will decrease. This verifies the effectiveness of the Siamese network, feature extraction model, and relevance gating model. Moreover, the performance of Scheme 5 decreases significantly, which verifies that directly attaching the retrieved knowledge data as context will introduce a large amount of noisy data, making it impossible for the large language model to focus on learning the mapping from the question to the logical form.
[0252] The question-and-answer method provided in this application can be applied to different scenarios. The following will use the medical question-and-answer scenario as an example for explanation.
[0253] Figure 8 This is a flowchart of a medical question-and-answer method provided in an embodiment of this application. See also... Figure 8 This medical question-and-answer method is executed by the terminal and the medical question-and-answer system, and includes:
[0254] 801. The terminal displays a medical Q&A interface and retrieves the medical questions entered in the medical Q&A interface.
[0255] See Figure 9 The medical Q&A interface displays an input box and a submit control. The user enters a medical question in the input box and clicks the submit control. The terminal then responds to the trigger operation of the submit control and retrieves the medical question entered in the input box.
[0256] 802. The terminal sends a medical question and answer request to the medical question and answer system, which carries the medical question.
[0257] 803. The medical question-and-answer system responds to the medical question-and-answer request by retrieving the medical question from the request and obtaining the medical question characteristics corresponding to the medical question.
[0258] 804. The medical question-and-answer system retrieves medical knowledge graphs based on the medical question, obtains medical knowledge data related to the medical question, and acquires the medical knowledge features corresponding to the medical knowledge data.
[0259] 805. The medical question-answering system performs attention processing on the features of medical knowledge to obtain attention features. Based on the features of medical questions and attention features, the system obtains the medical answer corresponding to the medical question through a large language model.
[0260] 806. The medical question-and-answer system sends the medical answer to the terminal.
[0261] 807. The terminal receives the medical answer and displays it in the medical Q&A interface.
[0262] See Figure 9 After a user enters a medical question in the input box and clicks the submit control, the terminal will display the medical question in the dialog area of the medical Q&A interface. Upon receiving the corresponding medical answer, the answer will be displayed below the medical question in the dialog area for the user to view. In addition to the submit control, the medical Q&A interface can also display a clear control and a retry control. The clear control clears the content entered in the input box, and the retry control indicates that an answer to the medical question is required.
[0263] This application implements a medical question-answering method based on a large language model, which greatly enriches the diversity and accessibility of medical services. By providing timely and accurate medical assistance information, it helps patients better understand their health status and conduct effective self-management. Furthermore, it can serve as an educational tool to improve users' medical skills. In addition, by providing personalized medical advice, it can meet users' individual needs, improve user satisfaction, and reduce the cost for users to obtain medical information.
[0264] Of course, the method provided in this application embodiment can also be applied to other scenarios, such as traffic planning scenarios, and this application embodiment does not limit it.
[0265] Figure 10 This is a schematic diagram of the structure of a question-and-answer device provided in an embodiment of this application. See also... Figure 10 The device includes:
[0266] Problem acquisition module 1001 is used to acquire problems and their corresponding problem characteristics;
[0267] The retrieval module 1002 is used to retrieve knowledge graphs based on questions to obtain knowledge data related to the questions. The knowledge data includes at least one data type among entity data, relation data, and subgraph data.
[0268] The feature acquisition module 1003 is used to acquire the knowledge features corresponding to the knowledge data. The knowledge features include at least one feature type among entity features, relation features, and subgraph features.
[0269] The attention processing module 1004 is used to perform attention processing on knowledge features to obtain attention features;
[0270] The answer acquisition module 1005 is used to obtain the answer to the question based on question features and attention features through a large language model.
[0271] In one possible implementation, see [link to relevant documentation]. Figure 11 The feature acquisition module 1003 includes:
[0272] The feature acquisition unit 1013 is used to acquire the knowledge features corresponding to each of the multiple text segments in the knowledge data belonging to any data type, based on the multiple text segments of the data type.
[0273] The average feature determination unit 1023 is used to determine the average features of the knowledge features corresponding to each of the multiple text segments.
[0274] The feature projection unit 1033 is used to project the average features to obtain the knowledge features corresponding to the knowledge data.
[0275] In one possible implementation, the attention processing module 1004 is used for at least one of the following:
[0276] Self-attention processing is applied to entity features to obtain entity attention features;
[0277] Self-attention processing is applied to relation features to obtain relation attention features;
[0278] Cross-attention processing is performed on entity features and subgraph features to obtain the first cross-attention feature. Cross-attention processing is performed on relation features and subgraph features to obtain the second cross-attention feature. The first cross-attention feature and the second cross-attention feature are combined to obtain the subgraph attention feature.
[0279] In one possible implementation, see [link to relevant documentation]. Figure 11 The answer retrieval module 1005 includes:
[0280] The logical form acquisition unit 1015 is used to acquire the logical form corresponding to the question based on the question features and attention features through a large language model.
[0281] Answer retrieval unit 1025 is used to retrieve the knowledge graph based on logical form and obtain the answer to the question.
[0282] In one possible implementation, the logical form acquisition unit 1015 is used to combine the problem features and attention features to obtain a first combined feature; the first combined feature is input into a large language model to obtain the logical form corresponding to the problem through the large language model.
[0283] In one possible implementation, the logical form acquisition unit 1015 is used to acquire the correlation between the problem features and the attention features; based on the correlation, the attention features are weighted to obtain weighted attention features; the problem features and the weighted attention features are combined to obtain a second combined feature; the second combined feature is input into a large language model to acquire the logical form corresponding to the problem through the large language model.
[0284] In one possible implementation, the logical form acquisition unit 1015 is used for at least one of the following:
[0285] Attention features include entity attention features. The correlation features between question features and entity attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance.
[0286] Attention features include relational attention features. The correlation features between the question features and relational attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the relational relevance.
[0287] Attention features include subgraph attention features. The correlation features between the question features and the subgraph attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the subgraph correlation.
[0288] In one possible implementation, the logical form acquisition unit 1015 is used for at least one of the following:
[0289] The entity attention features and entity relevance are multiplied element-wise to obtain the weighted entity attention features.
[0290] The element-wise product of relational attention features and relational relevance is used to obtain weighted relational attention features;
[0291] The weighted subgraph attention features are obtained by multiplying the subgraph attention features and subgraph relevance element by element.
[0292] In one possible implementation, the logical form acquisition unit 1015 is used to concatenate the initialization label features, problem features, and weighted attention features to obtain the second combined features.
[0293] In one possible implementation, the method is based on a question-answering model, which includes a feature extraction model and a large language model. The feature extraction model includes an embedding layer and an attention layer.
[0294] The embedding layer is used to obtain the problem features corresponding to the problem and the knowledge features corresponding to the knowledge data;
[0295] The attention layer is used to perform attention processing on knowledge features to obtain attention features;
[0296] Large language models are used to obtain the logical form corresponding to a question based on question features and attention features;
[0297] The attention layer includes at least one of a first self-attention layer, a second self-attention layer, and a cross-attention layer;
[0298] The first attention layer is used to perform self-attention processing on entity features to obtain entity attention features;
[0299] The second attention layer is used to perform self-attention processing on the relation features to obtain relation attention features;
[0300] The cross-attention layer is used to perform cross-attention processing on entity features and subgraph features to obtain the first cross-attention feature, and to perform cross-attention processing on relation features and subgraph features to obtain the second cross-attention feature. The first cross-attention feature and the second cross-attention feature are combined to obtain the subgraph attention feature.
[0301] In one possible implementation, the question-answering model also includes a relevance-gated model, which comprises a Siamese network and an output layer;
[0302] Siamese networks are used to obtain the correlation between problem features and attention features;
[0303] The output layer is used to weight the attention features based on relevance to obtain weighted attention features;
[0304] The twin network includes at least one of the first twin network, the second twin network, and the third twin network;
[0305] The first twin network is used to obtain the correlation features between the question features and the entity attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance.
[0306] The second Siamese network is used to obtain the relevance features between the question features and the relationship attention features. The relevance features include the relevance sub-features corresponding to each of the multiple text segments in the question. The average features of the relevance sub-features corresponding to each of the multiple text segments are normalized to obtain the relationship relevance.
[0307] The third Siamese network is used to obtain the correlation features between the question features and the subgraph attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the subgraph correlation.
[0308] In one possible implementation, see [link to relevant documentation]. Figure 11 The device also includes:
[0309] The model training module 1006 is used to acquire sample data, which includes sample questions, sample knowledge data related to the sample questions, and sample logical forms corresponding to the sample questions; acquire the initial question model; and, with the model parameters already trained in the large language model frozen, train the untrained model parameters in the question answering model based on the sample data to obtain the trained question answering model.
[0310] In one possible implementation, see [link to relevant documentation]. Figure 11 The retrieval module 1002 includes:
[0311] The first retrieval unit 1012 is used to retrieve related entities from the knowledge graph based on the entities in the question; and to obtain entity data of related entities from the knowledge graph.
[0312] In one possible implementation, see [link to relevant documentation]. Figure 11 The retrieval module 1002 includes:
[0313] The second retrieval unit 1022 is used to replace entities in the question with hidden tags to obtain the question after the hidden entities; and to retrieve relational data matching the question after the hidden entities from the knowledge graph based on the question after the hidden entities.
[0314] In one possible implementation, see [link to relevant documentation]. Figure 11 The retrieval module 1002 includes:
[0315] The third retrieval unit 1032 is used to linearize each triple in the knowledge graph to obtain linearized text. The triple includes a head entity, a relation, and a tail entity, and the linearized text is text that includes the head entity, relation, and tail entity. Based on at least one linearized text, at least one set of text data is created, and the head entities included in the same set of text data are the same. From the at least one set of text data, target text data that meets the relevance condition of the question is retrieved. Based on the target text data, subgraph data is obtained.
[0316] This application provides a question-answering scheme. After retrieving knowledge graphs based on questions and obtaining knowledge data related to the questions, knowledge features corresponding to the knowledge data are obtained, and attention processing is performed on the knowledge features to obtain attention features. This allows for the extraction of key features from the knowledge features and the removal of interference from noise features. In this way, when obtaining answers based on the question features and attention features corresponding to the questions, the large language model can be prevented from being misled by noise features, thus improving the accuracy of the answers.
[0317] It should be noted that the question-answering device provided in the above embodiments is only an example of the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device can be divided into different functional modules to complete all or part of the functions described above. In addition, the question-answering device and the question-answering method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0318] This application also provides a computer device, which includes a processor and a memory. The memory stores at least one computer program, which is loaded and executed by the processor to perform the operations performed in the question-and-answer method of the above embodiments.
[0319] Optionally, the computer device is provided as a terminal. Figure 12 A schematic diagram of the structure of a terminal 1200 provided in an exemplary embodiment of this application is shown.
[0320] Terminal 1200 includes a processor 1201 and a memory 1202.
[0321] Processor 1201 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1201 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1201 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1201 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1201 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0322] The memory 1202 may include one or more computer-readable storage media, which may be non-transitory. The memory 1202 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1202 are used to store at least one computer program, which is used by the processor 1201 to implement the question-and-answer method provided in the method embodiments of this application.
[0323] In some embodiments, the terminal 1200 may also optionally include: a peripheral device interface 1203 and at least one peripheral device. The processor 1201, memory 1202, and peripheral device interface 1203 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 1203 via a bus, signal line, or circuit board. Optionally, the peripheral device includes at least one of: a radio frequency circuit 1204, a display screen 1205, a camera assembly 1206, and a power supply 1207.
[0324] Peripheral device interface 1203 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 1201 and memory 1202. In some embodiments, processor 1201, memory 1202 and peripheral device interface 1203 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 1201, memory 1202 and peripheral device interface 1203 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0325] The radio frequency (RF) circuit 1204 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 1204 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1204 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 1204 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 1204 can communicate with other devices through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: metropolitan area networks (MANs), various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks (WLANs), and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 1204 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.
[0326] Display screen 1205 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 1205 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 1201 for processing. In this case, display screen 1205 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 1205, disposed on the front panel of terminal 1200; in other embodiments, there may be at least two display screens, disposed on different surfaces of terminal 1200 or in a folded design; in still other embodiments, display screen 1205 may be a flexible display screen, disposed on a curved or folded surface of terminal 1200. Furthermore, display screen 1205 may also be configured as a non-rectangular, irregular shape, i.e., a non-rectangular screen. The display screen 1205 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0327] The camera assembly 1206 is used to acquire images or videos. Optionally, the camera assembly 1206 includes a front-facing camera and a rear-facing camera. The front-facing camera is disposed on the front panel of the terminal 1200, and the rear-facing camera is disposed on the back of the terminal 1200. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 1206 may also include a flash. The flash may be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cool light flash, which can be used for light compensation at different color temperatures.
[0328] Power supply 1207 is used to power the various components in terminal 1200. Power supply 1207 can be AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 1207 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0329] Those skilled in the art will understand that Figure 12The structure shown does not constitute a limitation on terminal 1200 and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0330] Optionally, the computer device is provided as a server. Figure 13 This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1300 can vary significantly depending on its configuration or accuracy. It may include one or more Central Processing Units (CPUs) 1301 and one or more memories 1302. The memories 1302 store at least one computer program, which is loaded and executed by the processor 1301 to implement the methods provided in the various method embodiments described above. Of course, the server may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The server may also include other components for implementing device functions, which will not be elaborated upon here.
[0331] This application also provides a computer-readable storage medium storing at least one computer program, which is loaded and executed by a processor to perform the operations of the question-and-answer method described above.
[0332] This application also provides a computer program product, including a computer program loaded and executed by a processor to perform the operations performed by the question-and-answer method as described in the above embodiments.
[0333] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0334] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present application should be included within the protection scope of the present application.
Claims
1. A question-and-answer method, characterized in that, The method includes: Obtain the problem and its corresponding problem characteristics; Based on the question, a knowledge graph is retrieved to obtain knowledge data related to the question. The knowledge data includes at least one data type among entity data, relation data, and subgraph data. Obtain the knowledge features corresponding to the knowledge data, wherein the knowledge features include at least one feature type among entity features, relation features, and subgraph features; Attention processing is applied to the knowledge features to obtain attention features; Based on the question features and the attention features, the answer to the question is obtained through a large language model.
2. The method according to claim 1, characterized in that, The acquisition of knowledge features corresponding to the knowledge data includes: For any data type, based on multiple text segments in the knowledge data belonging to that data type, obtain the knowledge features corresponding to each of the multiple text segments; Determine the average feature of the knowledge features corresponding to each of the multiple text segments; The average features are projected to obtain the knowledge features corresponding to the knowledge data.
3. The method according to claim 1, characterized in that, The attention processing of the knowledge features to obtain attention features includes at least one of the following: The entity features are subjected to self-attention processing to obtain entity attention features; The relation features are subjected to self-attention processing to obtain relation attention features; Cross-attention processing is performed on the entity features and the subgraph features to obtain a first cross-attention feature. Cross-attention processing is performed on the relation features and the subgraph features to obtain a second cross-attention feature. The first cross-attention feature and the second cross-attention feature are combined to obtain the subgraph attention feature.
4. The method according to claim 1, characterized in that, The step of obtaining the answer to the question based on the question features and the attention features using a large language model includes: Based on the problem features and the attention features, the logical form corresponding to the problem is obtained through a large language model; The knowledge graph is retrieved based on the logical form described above to obtain the answer corresponding to the question.
5. The method according to claim 4, characterized in that, The step of obtaining the logical form corresponding to the problem through a large language model based on the problem features and the attention features includes: The problem features and the attention features are combined to obtain the first combined features; The first combined features are input into the large language model, and the logical form corresponding to the question is obtained through the large language model.
6. The method according to claim 4, characterized in that, The step of obtaining the logical form corresponding to the problem through a large language model based on the problem features and the attention features includes: Obtain the correlation between the problem features and the attention features; Based on the relevance, the attention features are weighted to obtain weighted attention features; The problem features and the weighted attention features are combined to obtain the second combined features; The second combined feature is input into the large language model, and the logical form corresponding to the question is obtained through the large language model.
7. The method according to claim 6, characterized in that, The process of obtaining the correlation between the problem features and the attention features includes at least one of the following: The attention features include entity attention features. The correlation features between the question features and the entity attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance. The attention features include relational attention features. The correlation features between the question features and the relational attention features are obtained. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the relational relevance. The attention features include subgraph attention features. The correlation features between the question features and the subgraph attention features are obtained. The correlation features include the correlation sub-features corresponding to multiple text segments in the question. The average features of the correlation sub-features corresponding to the multiple text segments are normalized to obtain the subgraph correlation.
8. The method according to claim 7, characterized in that, The attention features are weighted based on the relevance to obtain weighted attention features, which include at least one of the following: The entity attention features and the entity relevance are multiplied element-wise to obtain the weighted entity attention features; The element-wise product of the relation attention features and the relation relevance is used to obtain the weighted relation attention features; The weighted subgraph attention features are obtained by element-wise multiplying the subgraph attention features and the subgraph relevance.
9. The method according to claim 5, characterized in that, The combination of the problem features and the weighted attention features to obtain the second combined features includes: The initialization label feature, the problem feature, and the weighted attention feature are concatenated to obtain the second combined feature.
10. The method according to any one of claims 4-9, characterized in that, The method is based on a question-answering model, which includes a feature extraction model and a large language model. The feature extraction model includes an embedding layer and an attention layer. The embedding layer is used to obtain the problem features corresponding to the problem and the knowledge features corresponding to the knowledge data. The attention layer is used to perform attention processing on the knowledge features to obtain the attention features; The large language model is used to obtain the logical form corresponding to the question based on the question features and the attention features; The attention layer includes at least one of a first self-attention layer, a second self-attention layer, and a cross-attention layer; The first attention layer is used to perform self-attention processing on the entity features to obtain entity attention features; The second attention layer is used to perform self-attention processing on the relation features to obtain relation attention features; The cross-attention layer is used to perform cross-attention processing on the entity features and the subgraph features to obtain a first cross-attention feature, and to perform cross-attention processing on the relation features and the subgraph features to obtain a second cross-attention feature. The first cross-attention feature and the second cross-attention feature are combined to obtain the subgraph attention feature.
11. The method according to claim 10, characterized in that, The question-answering model also includes a relevance-gated model, which comprises a Siamese network and an output layer; The Siamese network is used to obtain the correlation between the problem features and the attention features; The output layer is used to perform weighted processing on the attention features based on the relevance to obtain weighted attention features; The twin network includes at least one of a first twin network, a second twin network, and a third twin network; The first Siamese network is used to obtain the correlation features between the question features and the entity attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the entity relevance. The second Siamese network is used to obtain the correlation features between the question features and the relational attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the question. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the relational relevance. The third Siamese network is used to obtain the correlation features between the problem features and the subgraph attention features. The correlation features include the correlation sub-features corresponding to each of the multiple text segments in the problem. The average features of the correlation sub-features corresponding to each of the multiple text segments are normalized to obtain the subgraph correlation.
12. The method according to claim 11, characterized in that, The process of training the question-answering model includes: Obtain sample data, which includes sample questions, sample knowledge data related to the sample questions, and sample logical forms corresponding to the sample questions; Obtain the initial problem model; With the already trained model parameters in the large language model frozen, the untrained model parameters in the question answering model are trained based on the sample data to obtain the trained question answering model.
13. The method according to claim 1, characterized in that, The process of retrieving knowledge graphs based on the question to obtain knowledge data related to the question includes: Based on the entities in the question, retrieve related entities from the knowledge graph; Obtain entity data of the relevant entities from the knowledge graph.
14. The method according to claim 1, characterized in that, The process of retrieving knowledge graphs based on the question to obtain knowledge data related to the question includes: The entities in the problem are replaced with hidden markers to obtain the problem with the hidden entities; Based on the question following the hidden entity, relational data matching the question following the hidden entity is retrieved from the knowledge graph.
15. The method according to claim 1, characterized in that, The process of retrieving knowledge graphs based on the question to obtain knowledge data related to the question includes: Each triple in the knowledge graph is linearized to obtain linearized text. The triple includes a head entity, a relation, and a tail entity. The linearized text is text that includes the head entity, the relation, and the tail entity. Based on at least one linearized text, create at least one set of text data, where the head entities included in the same set of text data are identical; From the at least one set of text data, retrieve target text data whose relevance to the question meets the relevant conditions; Based on the target text data, the subgraph data is obtained.
16. A question-and-answer device, characterized in that, The device includes: The problem acquisition module is used to acquire problems and their corresponding problem characteristics; The retrieval module is used to retrieve a knowledge graph based on the question to obtain knowledge data related to the question. The knowledge data includes at least one data type among entity data, relation data, and subgraph data. The feature acquisition module is used to acquire the knowledge features corresponding to the knowledge data, wherein the knowledge features include at least one feature type among entity features, relation features, and subgraph features; An attention processing module is used to perform attention processing on the knowledge features to obtain attention features; The answer acquisition module is used to obtain the answer corresponding to the question based on the question features and the attention features through a large language model.
17. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one computer program, which is loaded and executed by the processor to perform the operations of the question-and-answer method as described in any one of claims 1 to 15.
18. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to perform the operations of the question-and-answer method as described in any one of claims 1 to 15.
19. A computer program product, comprising a computer program, characterized in that, The computer program is loaded and executed by a processor to perform the operations of the question-and-answer method as described in any one of claims 1 to 15.