Knowledge enhancement and capsule network cooperative based logical reasoning method and device, and medium

By constructing an open knowledge database and a graph network database, and combining capsule networks with a large language model, the problem of integrating external knowledge and understanding complex logical structures in logical reasoning tasks by pre-trained language models is solved, achieving more efficient and accurate logical reasoning capabilities.

CN120278262BActive Publication Date: 2025-10-24SOUTH CHINA UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510243955.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-03
Publication Date
2025-10-24
Estimated Expiration
2045-03-03

AI Technical Summary

Technical Problem

Existing pre-trained language models struggle to effectively integrate external knowledge and understand complex logical structures in logical reasoning tasks, resulting in poor performance in such tasks.

Method used

By constructing a local database of public knowledge and a graph network database, and leveraging capsule networks in collaboration with large language models, knowledge enhancement and graph structure analysis are performed on logical reasoning texts. This includes vectorized knowledge retrieval, graph network expansion, semantic graph and connection graph construction, and dynamic routing algorithms to capture complex relationships between nodes and avoid over-smoothing of node features.

Benefits of technology

It significantly improves the model's logical reasoning ability and efficiency, enabling it to more accurately capture logical connections and structural information in text, thereby enhancing the accuracy of logical reasoning and the interpretability of the model, making it suitable for real-time reasoning scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120278262B_ABST
    Figure CN120278262B_ABST
Patent Text Reader

Abstract

The application discloses a kind of logic reasoning method, equipment and medium based on knowledge enhancement and capsule network coordination, wherein the method comprises: constructing public knowledge local database, locally deploying vectorization database and graph network database;According to the preliminary search of logic reasoning text, and based on graph network expansion search range;Logic text, question and related background knowledge are input into large language model, generate logic reasoning link, and integrate all contents, obtain knowledge enhanced logic reasoning text;According to the knowledge enhanced logic reasoning text, construct semantic graph and connection graph;Semantics graph and connection graph double graph are respectively imported into capsule network, and dynamic routing algorithm is used to promote low-level capsule to high-level capsule progression;Multiple high-level capsules in double graph are respectively executed average fusion operation to extract the global feature of graph;The global features of double graph are integrated by fusion strategy to form the final knowledge text feature, and the final option is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of large language models, and particularly relates to a logic reasoning method based on knowledge enhancement and capsule network cooperation, equipment and medium. BACKGROUND

[0002] In recent years, with the continuous development of question-answering datasets, the ability of machine reading comprehension (MRC) has become increasingly important. With the emergence of SQuAD, DROP and other datasets, the MRC field has made further development. Logical reasoning is an important task in MRC. The emergence of ReClor and LogiQA datasets has promoted the development of logical reasoning tasks. This emphasizes that models should not only have understanding capabilities, but also be able to integrate external knowledge to support the logical reasoning process, while understanding the logical structure in the text, such as context statements, hypotheses and potential fallacies. Although pre-trained language models (PLMs) perform well in capturing contextual semantic information, they have difficulties in dynamically integrating external knowledge and understanding the logical structure and complex relationships inherent in the context, which limits their performance in complex logical reasoning tasks. SUMMARY

[0003] To at least partially solve one of the technical problems existing in the prior art, the purpose of the present application is to provide a logic reasoning method based on knowledge enhancement and capsule network cooperation, equipment and medium.

[0004] The first technical solution adopted by the present application is:

[0005] A logic reasoning method based on knowledge enhancement and capsule network cooperation, comprising the following steps:

[0006] S1, constructing a public knowledge local database, deploying a vector database and a graph network database locally;

[0007] S2, performing preliminary retrieval according to the logic reasoning text, and expanding the retrieval range based on the graph network;

[0008] S3, inputting the logic text, the question and the related background knowledge into a large language model, generating a logic reasoning link, and integrating all the contents to obtain a logic reasoning text enhanced by knowledge;

[0009] S4, constructing a semantic graph and a connection graph according to the logic reasoning text enhanced by knowledge, thereby accurately capturing the logical association and structural information in the text to improve the analysis accuracy;

[0010] S5, import the semantic graph and the connection graph double graph into the capsule network respectively, use the dynamic routing algorithm to promote the low-level capsule to the high-level capsule, to accurately capture the complex correlation between nodes, effectively avoid the phenomenon of excessive smoothing of node features in traditional GCN, and improve the node recognition, provide more rich and accurate feature representation for subsequent logical reasoning;

[0011] S6, respectively, perform average fusion operation on multiple high-level capsules in the double graph to extract global features of the graph; then, integrate the global features of the double graph through a fusion strategy to form the final knowledge text features and obtain the final options.

[0012] Further, the disclosed knowledge local database is constructed, and a vectorization database and a graph network database are deployed locally, including:

[0013] Extract relevant background knowledge, logical rules and common logical fallacies from existing open source datasets;

[0014] Use a large model to extract key knowledge from the collected text; wherein the key knowledge includes coarse-grained summary knowledge and entity metadata;

[0015] Vectorize the coarse-grained summary knowledge and store the vectorized knowledge in the vectorization database for subsequent knowledge retrieval;

[0016] Construct a graph network according to the extracted entity metadata; wherein the nodes in the graph network represent each knowledge document, and the knowledge document contains knowledge entities;

[0017] Extract the co-occurrence relationship of knowledge documents from the graph network, construct the edge from knowledge document to knowledge document, and the edge represents the association relationship between entities and knowledge documents.

[0018] Further, the initial retrieval is performed according to the logical reasoning text, and the retrieval range is expanded based on the graph network, including:

[0019] Through calculating the similarity between the logical reasoning text vector and the local knowledge document vector, the initial retrieval is performed to identify the most relevant knowledge documents;

[0020] Based on the constructed graph network, the retrieval range is expanded: by analyzing the co-occurrence relationship and association between the initially retrieved knowledge text and other knowledge, more relevant background knowledge documents are identified and included to ensure that the expanded document set provides more comprehensive background context information.

[0021] Further, the logical text, question and related background knowledge are input into a large language model to generate a logical reasoning link, and all contents are integrated to obtain a knowledge-enhanced logical reasoning text, including:

[0022] The retrieved relevant knowledge documents, logical reasoning texts and problems are merged to obtain an overall large paragraph I i :

[0023] I i =concat(d 扩展 ,C i ,Q i )

[0024] In the formula, d 扩展 represents the extended search knowledge document, C i represents the logical reasoning text, and Q i represents the question;

[0025] The merged overall large paragraph I i is input into a large language model to generate a logical thinking reasoning link G i . The thinking link G i is placed behind the overall large paragraph I i to form the final enhanced logical reasoning text R i :

[0026] R i =concat(C i ,Q i ,G i )

[0027] Further, the construction of the semantic graph and the connection graph according to the knowledge-enhanced logical reasoning text comprises:

[0028] By combining the original logical text C, the question Q, the thinking reasoning path G and the option answer O, a structure of [CLS]C[SEP]Q[SEP]G||O[SEP] is constructed. The structure is input into a large language model. The [CLS] feature vector in the obtained multiple alternative answers is mapped through a linear layer, and then the probability distribution of each alternative answer is obtained through a Softmax activation function, which is specifically expressed as: P(O1, O2, O3, O4|CQG). Finally, the cross-entropy loss function is used to perform gradient backpropagation operation on the model to realize the optimization and update of the model parameters.

[0029] First, the text is constructed into a semantic graph and a connection graph according to direct conjunctions and punctuation: the context is divided into nodes, and the association between the nodes is used as the edge to construct the architecture of the graph. Such associations are divided into direct and indirect conjunctions, and each node represents a text paragraph connected by logical associations. Adopting conjunctions and punctuation marks as two types of connection links, the semantic graph and the connection graph are constructed accordingly.

[0030] The structural framework of [CLS]C[SEP]Q[SEP]G||O[SEP] is input into a pre-trained large language model to obtain an initial feature vector V of each node i The specific input form is as follows:

[0031] input=[CLS]+C+[SEP]+Q+[SEP]+G+[SEP]+O+[SEP]

[0032] V i =RoBERTa_Large(input)

[0033] In the constructed connection graph and semantic graph, each node contains a plurality of Tokens, and the representation of the Token is as follows: The feature vector corresponding to the Token is:

[0034] The feature vector corresponding to each node not only includes the semantic content of the node itself, but also fuses the position embedding information of the node in the text structure.

[0035] Further, in order to maintain the sequence relationship of the nodes in the text context, a position embedding technology is introduced: the position embedding technology aims to add position features to the vector representation of each node, so that the model can effectively identify the relative positions of different nodes in the text, and the specific expression is:

[0036]

[0037] n i =s i +PE(s i )

[0038] In the formula, n i represents the node feature after adding the original node and the position code, and for each enhanced logical reasoning text R i , there is a relationship between the graph g i corresponding to a specific option O i :

[0039] g i =(N i ,E i )

[0040] In the formula, E i represents the edge connecting the node N i , and E i includes the edges of conjunctions and punctuation marks; the set N i is defined as: N i :{n1,n2,…,m k}.

[0041] Further, the semantic graph and the connection graph are respectively imported into the capsule network, and a dynamic routing algorithm is used to promote the low-level capsules to the high-level capsules to accurately capture the complex correlation between nodes, including:

[0042] The node features of the semantic graph and the connection graph are respectively input into the capsule network, and through the process of iterative multiple dynamic routing, the process of approximating high-level capsules by low-level capsules is obtained K short-term information vector features, K is a preset hyperparameter, and the short-term local text information in each graph is extracted;

[0043] Among them, the dynamic routing mechanism in the capsule network adaptively adjusts the path of information transmission according to the input.

[0044] Further, the average fusion operation is respectively performed on the plurality of high-level capsules in the double graphs to extract the global features of the graphs, and then the global features of the double graphs are integrated through a fusion strategy to form the final knowledge text features, and the final options are obtained, including:

[0045] The features of all high-level capsules in each graph are summed up by averaging The global vector representation of the double graphs is obtained

[0046] An interactive attention component is used to associate each option with the feature vector of the question and In order to more effectively grasp the logical text information and logical structure;

[0047] An interactive attention component is used to measure the similarity between the global graph vector representation and each option, question, and the similarity is regarded as a weight and distributed to Vector representation;

[0048] After completing the interactive attention mechanism component, in order to improve the performance of the model, the feature vectors Option representation V option And question representation V' question Are associated and input into a fully connected neural network to obtain the final feature representation;

[0049] According to the feature representation, the probability distribution of each candidate option is calculated, and the candidate option corresponding to the maximum probability is selected as the prediction result.

[0050] The second technical scheme adopted by the present application is:

[0051] An electronic device includes a processor and a memory having stored therein at least one instruction, at least one program, a code set or instruction set, which is loaded and executed by the processor to implement the knowledge-enhanced and capsule network collaborative logical reasoning method as described above.

[0052] The third technical solution adopted by the present application is:

[0053] A computer-readable storage medium having stored therein at least one instruction, at least one program, a code set or instruction set, which is loaded and executed by a processor to implement the knowledge-enhanced and capsule network collaborative logical reasoning method as described above.

[0054] The fourth technical solution adopted by the present application is:

[0055] A computer program product or computer program includes computer instructions stored in a computer-readable storage medium. The processor of the computer device can read the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to make the computer device execute the method described above.

[0056] Compared with the prior art, the present application has the following advantages:

[0057] (1) The present application retrieves local knowledge related to the original logical reasoning text through vectorized knowledge base and graph network retrieval technology, and inputs the knowledge after merging into a large model to generate a logical thinking reasoning link, and combines the reasoning link with the original text to build a knowledge-enhanced input representation. This mechanism solves the problem of lack of explicit logical support in traditional methods, significantly improving the reasoning ability of the model.

[0058] (2) The present application proposes a double-graph construction method for logical reasoning of machine reading comprehension. This method uses conjunctions and punctuation marks as two types of edges to construct semantic graphs and connection graphs. In this way, the model can more accurately capture the logical associations and structural information in the text.

[0059] (3) The application proposes a method based on a capsule network to replace the traditional graph convolutional network (GCN) for extracting node features on the graph. The capsule network can capture the complex relationship between nodes through a dynamic routing algorithm, avoiding the problem of excessive smoothing of node features in traditional GCN, and enhancing the recognition of nodes. Compared with GCN, the capsule network can better capture the spatial relationship and hierarchy of nodes in the graph, so that the features of important nodes can be more accurately extracted and expressed. The node feature vector extracted by the capsule network will be used to construct the overall features of the graph, improving the performance of graph reasoning. This method not only avoids the limitations of GCN, but also improves the reasoning ability and efficiency of the model, especially when dealing with tasks with complex logic and multiple relationships, the capsule network shows significant advantages. The dynamic routing mechanism in the capsule network can adaptively adjust the path of information transmission according to the input. In the graph structure, it can better capture the hierarchical relationship and dependency between nodes. For example, in a semantic graph, the dynamic routing can automatically adjust the weight of information transmission according to the semantic association strength between nodes, so that information can be more effectively transmitted between nodes, enhancing the model's perception of graph structure.

[0060] (4) The method not only improves the accuracy of logical reasoning, but also improves the efficiency and scalability of the model. This method not only provides an interpretable reasoning path for machine reading comprehension, but also makes it have the potential to land in real-time reasoning scenarios, providing an important reference for model architecture innovation in knowledge-intensive NLP tasks. BRIEF DESCRIPTION OF DRAWINGS

[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following introduces the drawings of the related technical solutions in the embodiments of the present application or the prior art. It should be understood that the drawings in the following introduction are only for the convenience of clearly describing some embodiments in the technical solutions of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.

[0062] Figure 1 is a step flow chart of a logical reasoning method based on knowledge enhancement and capsule network cooperation in an embodiment of the present application;

[0063] Figure 2 is a local knowledge base and graph network knowledge base structure diagram in an embodiment of the present application.

[0064] Figure 3 is a network structure diagram based on the knowledge enhancement and capsule network method in an embodiment of the present application. DETAILED DESCRIPTION

[0065] Embodiments of the present application are described below in detail with reference to the accompanying drawings, examples of which are shown in the drawings, wherein the same or similar notations represent the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as a limitation of the present application. For the step numbers in the following embodiments, they are only set for the convenience of explaining the description, and the order between the steps is not limited in any way, and the execution order of each step in the embodiments can be adaptively adjusted according to the understanding of those skilled in the art.

[0066] In the description of the present application, it should be understood that the orientation description, such as the orientation or position relationship indicated by the upper, lower, front, rear, left, right, etc. is based on the orientation or position relationship shown in the drawings, and is only for the convenience of describing the present application and simplifying the description, and cannot be understood as indicating or implying that the device or element indicated must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation of the present application.

[0067] In the description of the present application, the meaning of several is one or more, and the meaning of multiple is more than two, greater than, less than, more than, etc. are understood as not including the number, and above, below, etc. are understood as including the number. If it is described as first, second, it is only used for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features or the order of indicated technical features.

[0068] In the description of the present application, unless otherwise explicitly limited, the words such as setting, installing, connecting, etc. should be understood in a broad sense, and those skilled in the art can reasonably determine the specific meaning of the above words in the present application in combination with the specific content of the technical solution.

[0069] In order to solve the shortcomings of PLMs, the present application proposes a logical reasoning algorithm based on knowledge enhancement and capsule network cooperation. Specifically, for each logical reasoning problem, first, the merged text of the original logical text and the problem is retrieved and matched with the local knowledge base to retrieve relevant background knowledge, and after merging, the large language model is input to generate auxiliary logical thinking reasoning link. The reasoning chain is spliced with the original logical text and the problem to form an enhanced logical reasoning text. This innovative design enables the model to explicitly obtain potential premise assumptions and implicit logical relationships, providing information support for subsequent graph structure modeling.

[0070] On this basis, previous methods build graphs based on entities in the context, extract relationships from text, and aggregate messages using graph convolution networks (GCN). However, there is still much room for improvement. For example, overuse of GCN can cause node smoothing, making the features of nodes tend to be similar and lose their distinguishing features. Therefore, in logical reasoning, more attention should be paid to using more effective methods of node feature extraction in graph structure. Compared with previous methods, the present invention uses a capsule network for graph node feature extraction, improving the performance of the model, and significantly enhancing the completeness of semantic representation through knowledge retrieval.

[0071] Embodiment 1

[0072] As Figure 1 shown, the present embodiment provides a knowledge-enhanced and capsule network-based logical reasoning method, comprising the following steps:

[0073] S1, build a public knowledge local database, and locally deploy a vectorized database and a graph network database.

[0074] Specifically, the public knowledge local database is constructed, relevant information is obtained from two public logical reasoning datasets, Wikipedia and CommonsenseQA, and then a vectorized database and a graphical knowledge base are locally deployed to ensure rigorous construction of the knowledge system.

[0075] S2, perform preliminary retrieval according to the logical reasoning text, and expand the retrieval range based on the graph network.

[0076] Specifically, the logical paragraph and the question input link are implemented via vector matching and graph network node co-occurrence technology to realize multi-path recall retrieval of local relevant knowledge, enriching the relevant background knowledge system of logical questions.

[0077] S3, input the logical text, question and related background knowledge into a large language model to generate a logical reasoning link, and integrate all the content to obtain a knowledge-enhanced logical reasoning text.

[0078] The present embodiment retrieves relevant knowledge through a local knowledge base and a graph network, and uses an open-source large language model to perform preliminary logical reasoning on logical reasoning questions and original logical text. Then the reasoning information is used as enhancement information, and is combined with the original logical text and question, and then input into the trained language model.

[0079] S4, according to the knowledge-enhanced logical reasoning text, construct a semantic graph and a connection graph, thereby accurately capturing the logical association and structural information in the text to improve analysis accuracy.

[0080] This embodiment uses conjunctions and punctuation marks as two types of edges to construct double graphs (semantic graph and connection graph) for knowledge-enhanced logical text.

[0081] S5, the semantic graph and the connection graph double graph are respectively imported into the capsule network, and a dynamic routing algorithm is used to promote the low-level capsule to the high-level capsule to accurately capture the complex correlation between nodes and effectively avoid the node feature over-smoothing phenomenon in the traditional GCN, thereby improving the node recognition degree and providing more rich and accurate feature representation for subsequent logical reasoning.

[0082] This embodiment proposes a method based on a capsule network (Capsule Network) to replace the traditional graph convolutional network (GCN) to extract node features on the graph. The capsule network can capture the complex relationship between nodes through a dynamic routing algorithm, avoiding the node feature over-smoothing problem in the traditional GCN, and enhancing the node recognition degree.

[0083] S6, an average fusion operation is respectively performed on multiple high-level capsules in the double graph to extract global features of the graph; then, the global features of the double graph are integrated through a fusion strategy to form the final knowledge text features, and the final option is obtained.

[0084] The above method will be explained in detail in combination with the accompanying drawings and specific embodiments.

[0085] (1) Saving of disclosed knowledge and construction of knowledge base

[0086] In order to improve the performance of logical reasoning tasks, this embodiment first saves the relevant disclosed knowledge from two publicly disclosed logical reasoning data sets, Wikipedia and CommonsenseQA. These knowledge includes but is not limited to background knowledge, logical rules, common logical fallacies, etc. Specifically, the following types of disclosed knowledge are stored locally:

[0087] Background knowledge: including domain knowledge, common sense, historical events, etc. related to logical reasoning problems. These knowledge can help the model better understand the problem background and provide more accurate reasoning results.

[0088] Logical rules: including basic logical reasoning rules such as deductive reasoning, inductive reasoning, analogy reasoning, etc. These rules are the basis of logical reasoning and help the model make correct judgments when dealing with complex logical problems.

[0089] Common logical fallacies: including common logical errors and fallacies such as fallacy of equivocation, causality inversion, and generalization. These knowledge can help the model identify and avoid logical errors and improve the accuracy of reasoning.

[0090] As an implementation, refer to Figure 2 ,Figure 2 To construct the schematic diagram of the vectorized knowledge base detailed structure, the construction method is as follows:

[0091] 1) Extract relevant background knowledge, logical rules and common logical fallacies from the following open source datasets:

[0092] Wikipedia: Wikipedia is a widely used knowledge base that contains a wealth of background knowledge and common sense.

[0093] CommonsenseQA: A dataset containing common sense questions and answers, which helps the model understand common logical relationships and background knowledge.

[0094] 2) Knowledge extraction: Use large models (such as ChatGLM2-6b) to extract key knowledge from collected text. Specific extraction strategies include:

[0095] Coarse-grained document-level summary: Use ChatGLM2-6b to generate a summary of the knowledge document, helping to quickly understand the main content of the knowledge document and retrieve relevant knowledge. Specifically as shown in equation (1):

[0096] s k =ChatGLM2_6b(d k ) (1)

[0097] Fine-grained entity-level dialogue generation: Generate query-answer pairs in knowledge documents through RefGPT to provide more detailed entity information.

[0098] (q {k0} ,a {k0} ),(q {k1} ,a {k1} ),…=RefGPT(d k )

[0099] 3) Knowledge vectorization: Vectorize coarse-grained summary knowledge. Given the summary, obtain embedding vectors through sentence embedding models (such as BGE and SGPT), as shown in equation (2):

[0100] e {sk} = SentEmbed(s k ) (2)

[0101] 4) Vectorized knowledge base construction: Store the vectorized knowledge in a vector database for subsequent knowledge retrieval.

[0102] 5) Construction of graph structure knowledge base: Nodes represent knowledge entities, and edges represent the association between entities. The specific steps are as follows:

[0103] Graph structure construction: Extract metadata of key entities from these documents using ChatGLM2-6b, and construct an initial graph structure from the extracted entity metadata, where nodes represent each knowledge document containing knowledge entities (such as historical event names, characters, etc.)

[0104] Inter-document edge construction: Extract the co-occurrence relationship of knowledge documents from the initial graph structure, construct knowledge document to knowledge document edges, and edges represent the association between entities and knowledge documents, such as co-occurrence entities between two documents. Then, further associate the documents according to events and characters to ensure that the relationship between knowledge documents is more comprehensive, thereby constructing an inter-document graph network. As shown in equations (3)-(4):

[0105] E={(d i ,d j )|d i ,d j ∈D,i≠j} (3)

[0106] G=(D,E) (4)

[0107] (2) Vectorized knowledge retrieval

[0108] The vectorized database is an important part of this framework. In order to retrieve knowledge from the vectorized database, the original logical reasoning text will be input into the same sentence embedding model to obtain the embedding vector. Get the background knowledge document with the highest cosine similarity with the original logical text in the local knowledge base as the external knowledge to assist the large language model in generating responses. As shown in equation (5):

[0109]

[0110] (3) Multi-path recall knowledge retrieval

[0111] This embodiment performs preliminary retrieval by calculating the similarity between the logical reasoning text vector and the local knowledge document vector, and identifies the most relevant knowledge documents to the query. This process ensures accurate capture of logical reasoning text and problem intent, so that the preliminary retrieval result can highly meet the requirements of logical reasoning text. In order to further enrich the retrieval results, this embodiment uses the previously constructed graph structure to expand the retrieval range. By analyzing the co-occurrence relationship and association between the preliminary retrieved logical text and other knowledge, the system can identify and include more relevant background knowledge documents, ensuring that the expanded document set provides more comprehensive background context information. As shown in equation (6):

[0112] d 扩展 =d * ∪{(d j |(d i ,d j ))∈E,di ∈d *} (6)

[0113] (4) Logic reasoning enhancement and text merging

[0114] After the preliminary retrieval and graph network expansion, the retrieved relevant knowledge documents, the original logic text and the problem are answered by logical reasoning. The specific steps are as follows:

[0115] Text merging: merge the retrieved relevant knowledge documents, the logic reasoning text and the problem to obtain the overall large paragraph I i .

[0116] I i =concat(d 扩展 ,C i ,Q i ) (7)

[0117] Large model generates thinking reasoning link: input the merged overall large paragraph I i to the open source large model ChatGLM2-6b to generate the logic thinking reasoning link G i , and place the thinking link behind the overall large paragraph I i to form the final enhanced logic reasoning text R i . As shown in equations (8)-(9):

[0118] G i =ChatGLM2_6b(I i ) (8)

[0119] R i =concat(C i ,Q i ,G i ,) (9)

[0120] (5) Double graph construction of enhanced logic reasoning text

[0121] The core of the embodiment focuses on solving the multiple-choice question challenge in the field of logical reasoning. Specifically, the embodiment combines the original logical text (C), the question (Q), the thinking reasoning path (G) and the option answer (O) to construct the structure of [CLS]C[SEP]Q[SEP]G||O[SEP], and inputs the structure into the well-trained language model PLM. Then, the [CLS] feature vector in the obtained multiple alternative answers is mapped through a linear layer, and the probability distribution of each alternative answer is obtained through the Softmax activation function, which is specifically expressed as: P(O1, O2, O3, O4|CQG). Finally, the cross-entropy loss function is used to perform gradient backpropagation operation on the model to realize the optimization and update of the model parameters. For details, please refer to formulas (10)-(11).

[0122] L = -∑logP (o true |C,Q,G) (10)

[0123]

[0124] Wherein, O ij represents the option j in the i-th original logical text, C i , Q i , G i and O i respectively represent the original logical text, the question, the thinking reasoning link and the option feature representation.

[0125] At the encoding layer, the model of the embodiment is constructed according to the direct conjunction association and punctuation. The context is divided into nodes, and the association between them is used as the edge to construct the graph architecture. Such association is divided into direct and indirect conjunction. Each node represents a text paragraph connected by logical association, which makes it more like a logical graph than a sequence structure.

[0126] The display connection conveys various relationships including causality, contrast, condition, etc. In identifying these direct connections, the model of the embodiment adopts a set of established conjunction keywords and further strengthens them by using the NLTK root extraction technology. This means can stably identify various inflectional forms and ensure accurate detection of logical relationships. By using these conjunctions to distinguish different nodes, the model can better learn the logical structure and association in the text. Specifically, these conjunctions connect sentences, which strengthens the clarity of the logical relationship between sentences.

[0127] Implicit connections are hidden in continuous text segments separated by punctuation marks such as commas. Identifying these separators is of great importance as they play a symbolic role in distinguishing different text passages. Their identification helps the model accurately grasp the boundaries between sentences, thereby enhancing its overall contextual understanding ability. For each sample, only the context and option content are segmented, while the question part is excluded, because the question part lacks the necessary logical connotations. Adopting conjunctions and punctuation marks as two types of connection links, a semantic graph and a connection graph are constructed. The clever use of conjunctions and punctuation marks builds a more complex structure system, which can capture deep logical relationships beyond simple adjacency relationships. For example, causal conjunctions such as "because" and "therefore" can create connection links representing causal relationships; and contrastive conjunctions such as "but" and "however" can capture opposing ideas. These logical connection links play a crucial role in understanding the underlying meaning of the text, far beyond simple sequential links.

[0128] In the model encoding layer constructed in this embodiment, first, the original feature embedding of each node is obtained. For this purpose, the structure framework of [CLS]C[SEP]Q[SEP]G||O[SEP] is input into the pre-trained language model (PLMs), so as to obtain the initial feature vector of each node. In this embodiment, RoBERTa_Large is selected as the core encoder. The specific input form is listed in formulas (12)-(13):

[0129] input=[CLS]+C+[SEP]+Q+[SEP]+G+[SEP]+O+[SEP] (12)

[0130] V i =RoBERTa_Large(input) (13)

[0131] In the constructed connection graph and semantic graph, each node contains multiple Tokens, and the representation of Token is as follows: The feature vector corresponding to Token is: In order to better utilize the initial node vector representation, the S Token vector representation contained in the initial node is added in this embodiment, as shown in formula (14):

[0132]

[0133] The feature vector corresponding to each node not only includes the semantic content of the node itself, but also fuses the position embedding information of the node in the text structure. In order to maintain the sequence relationship of the nodes in the text context, the position embedding technology is adopted in the embodiment. The technology aims to add position features to the vector representation of each node, so that the model can effectively identify the relative positions of different nodes in the text. For specific expressions, please refer to formulas (15)-(16).

[0134]

[0135] n i =s i +PE(s i ) (16)

[0136] wherein n i represents the node feature after adding the original node and the position code. For each enhanced logical reasoning text R i , the graph g i corresponding to a specific option O i is as shown in formula (17):

[0137] g i =(N i ,E i ) (17)

[0138] wherein E i represents an edge connecting nodes N i , and E i includes edges of conjunctions and punctuation marks. The set N i can be defined as: N i :{n1,n2,…,m k}.

[0139] (6) Capsule network construction and node feature extraction

[0140] After completing the coding task of the node, the reasoning phase of the double graph construction is entered. The traditional logical deduction model tends to use a graph convolutional neural network to extract the feature information of the node. This means that through the mapping of the spatial dimension, the feature vectors of adjacent nodes are integrated into the center node, thereby improving the semantic expression ability of the center node. However, with the increase of the graph convolution level, the features between nodes tend to be homogeneous, that is, the over-smoothing phenomenon occurs, which reduces the recognition of the node features and weakens the analysis efficiency of the model. The traditional graph convolutional neural network method can be seen in formula (18):

[0141]

[0142] wherein A is an adjacency matrix representing the connection relationship between nodes in the constructed graph structure. The degree matrix For the implementation of the standardization of the adjacency matrix, aiming to weaken the interference effect of abnormal values. After the construction of the adjacency matrix, the model will proceed to process the features of each node. This processing procedure covers the execution of linear mapping on the feature vector by utilizing a trainable weight matrix, and then adopts a Sigmoid activation function to achieve the transformation and adjustment of the features, as shown in equation (19):

[0143] α k =σ(W α (n k )+b α ) (19)

[0144] After information propagation, the graph convolutional network will fuse the initial features of the nodes with the features after message passing, as shown in equation (20):

[0145]

[0146] wherein represents the node feature representation after the graph convolutional network. The above calculation process is a specific implementation method of the traditional graph convolutional network. However, through research, it is found that the traditional graph convolution method has problems such as causing the node features to be excessively smooth and the effect being poor.

[0147] Therefore, further, after obtaining the node features of the logical graph and the structural graph, as shown in equation (21), by inputting the node features of the two graphs into the capsule network respectively, through the process of iteratively routing multiple times, and by the process of low-level capsules approximating high-level capsules, K short-term information vector features are obtained, K being a preset hyperparameter, and the short-term local text information in each graph is extracted. First, each node feature Figure 3 is mapped into m candidate capsule vectors, as shown in equation (21):

[0148] u k / m =W m (21)

[0149] Next, the capsule weights are determined through multiple routing iterations, and the detailed iteration process is shown in equations (22)-(25):

[0150]

[0151] wherein m is the set number of capsules, W m is a double mapping matrix, is a coupling coefficient, is the short-term market information feature after the nonlinear activation function. t is the iteration number, and through 3 iterations, the coupling coefficient is optimized, so that the high-level capsules ​Adaptively focusing on local short-term key information achieves fine-grained temporal focus, enabling the model to better reflect knowledge-enhanced logical reasoning texts by clustering and extracting important node features.

[0152] Capsule networks represent nodes using capsules. Each capsule can learn different aspects of the node's attributes, such as the node's characteristics along different semantic dimensions. For example, for a sentence node in a text graph, different capsules can learn information about the sentence's semantic theme, grammatical structure, and sentiment, resulting in a more comprehensive and accurate representation of the node.

[0153] The dynamic routing mechanism in capsule networks adaptively adjusts the information transfer path based on input. In graph structures, it better captures the hierarchical relationships and dependencies between nodes. For example, in a semantic graph, dynamic routing automatically adjusts the weight of information transfer based on the strength of semantic connections between nodes, enabling more efficient information propagation between nodes and enhancing the model's perception of graph structure. Capsule networks transfer information through operations between vectors, better preserving node feature information.

[0154] During the classification and feature fusion process, the capsule network can perform more detailed processing based on the attribute information of the node, avoiding excessive aggregation and loss of information, thereby providing richer and more accurate feature representation for subsequent logical reasoning.

[0155] Finally, the features of all high-level capsules in each graph are Perform average summation to obtain the global vector representation of the dual image (7) Answer prediction

[0156] In the logic deduction task, the original logic text and the question constitute the core information, which plays a key role in the model's accurate grasp of the text meaning. This embodiment uses the interactive attention component to combine the feature vectors of the original logic text and the question with the Connect them to more effectively grasp the logical text information and logical structure. For details, see formulas (26)-(28):

[0157] Q=V option / question W Q (26)

[0158] K=V k W k (27)

[0159] V=V k W v (28)

[0160] Among them, W Q , W k , Wv is a learnable parameter matrix, and Q, K, and V can be obtained after mapping.

[0161] Subsequently, the embodiment adopts an interactive attention component to measure the similarity between the global graph vector representation and each option and question, and regards the similarity as a weight assigned to the vector representation. This is intended to enable the vector representation to more fully absorb the information of the original logical text and the question, thereby more effectively performing the logical reasoning task. For details, see formulas (29)-(32).

[0162]

[0163] Att(Q,K,V)=softmax(A)·V (30)

[0164]

[0165] After completing the interactive attention mechanism component, in order to improve the performance of the model, the feature vector is combined with each option representation V option and question representation V′ question , and then input into a fully connected neural network to obtain the final feature representation. The probability distribution of each candidate is calculated by applying the normalized exponential function (Softmax). Finally, the candidate corresponding to the maximum probability is selected as the prediction result. For details, see formula (33):

[0166]

[0167] In summary, the method of the present application has at least the following advantages compared with the prior art:

[0168] 1) Saving of disclosed knowledge and construction of knowledge base: background knowledge, logical rules and common logical fallacies are extracted from the disclosed data set to construct a rich knowledge base. Specifically, open source data sets such as Wikipedia and CommonsenseQA are used to ensure the comprehensiveness and diversity of the knowledge.

[0169] 2) Construction and retrieval of local knowledge base: by constructing a local vectorized database and a graph network database, the retrieval of background knowledge and other knowledge of the logical reasoning text is improved. The retrieved relevant knowledge documents and the original logical text are input into the open source large language model to generate preliminary logical reasoning ideas, and these answers are merged with the original logic and the relevant knowledge documents to form enhanced logical reasoning text.

[0170] 3) Capsule Network Construction and Node Feature Extraction: We propose a method based on capsule networks (Capsule Networks) to replace traditional graph convolutional networks (GCNs) for extracting node features from graphs. Capsule networks utilize a dynamic routing algorithm to capture complex relationships between nodes, avoiding the over-smoothing of node features found in traditional GCNs and enhancing node discernibility. Compared to GCNs, capsule networks better capture the spatial relationships and hierarchical structure of nodes in a graph, enabling more accurate extraction and representation of important node features. Node feature vectors extracted by capsule networks are used to construct the overall graph features, enhancing the performance of graph reasoning. This method not only avoids the limitations of GCNs but also improves the model's reasoning power and efficiency. Capsule networks demonstrate significant advantages, particularly when handling tasks with complex logic and multiple relationships. The dynamic routing mechanism in capsule networks adaptively adjusts the information transmission path based on the input. In graph structures, they better capture hierarchical relationships and dependencies between nodes. For example, in a semantic graph, dynamic routing can automatically adjust the weight of information transmission based on the strength of semantic associations between nodes, allowing information to be transmitted more efficiently between nodes and enhancing the model's ability to perceive the graph structure.

[0171] 4) This method not only improves the accuracy of logical reasoning but also enhances the efficiency and scalability of the model. This method not only provides an explainable reasoning path for machine reading comprehension, but its network design also makes it potentially applicable in real-time reasoning scenarios, providing an important reference for model architecture innovation for knowledge-intensive NLP tasks.

[0172] Example 2

[0173] An embodiment of the present invention further provides an electronic device, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the following Figure 1 A logical reasoning method based on the collaboration of knowledge enhancement and capsule network is shown.

[0174] It can be understood that the memory can include a random access memory (RAM) and can also include a read-only memory (ROM). Optionally, the memory includes a non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, codes, code sets or instruction sets. The memory can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for at least one function, instructions for implementing various method embodiments described above, and the like; and the data storage area can store data created according to the use of the server, and the like.

[0175] The processor can include one or more processing cores. The processor connects various parts within the entire server through various interfaces and lines, executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory. Optionally, the processor can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor can be integrated with one or a combination of a central processing unit (CPU) and a modem. Among them, the CPU mainly processes operating systems and application programs, etc.; the modem is used to process wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor, but can be implemented by a separate chip.

[0176] Since the electronic device is an electronic device corresponding to the logical reasoning method based on knowledge enhancement and capsule network cooperation of the embodiment of the application, and the principle of solving problems of the electronic device is similar to that of the method, the implementation of the electronic device can be referred to the implementation process of the above-mentioned method embodiments, and the repeated parts will not be described again.

[0177] Embodiment 3

[0178] The embodiment of the application further provides a computer readable storage medium, wherein the storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by a processor to implement the logical reasoning method based on knowledge enhancement and capsule network cooperation as shown in Figure 1 ​

[0179] Those skilled in the art can understand that all or part of the steps of various methods of the above-mentioned embodiments can be completed by instructing the relevant hardware through a program, and the program can be stored in a computer readable storage medium, including Read-Only Memory (ROM), Random Access Memory (RAM), Programmable Read-only Memory (PROM), Erasable Programmable Read Only Memory (EPROM), One-time Programmable Read-Only Memory (OTPROM), Electrically-Erasable Programmable Read-Only Memory (EEPROM), Compact Disc Read-Only Memory (CD-ROM) or other optical disk storage, magnetic disk storage, magnetic tape storage, or any other medium that can be used to carry or store data which can be read by a computer.

[0180] Since the storage medium is a storage medium corresponding to the logic reasoning method based on knowledge enhancement and capsule network cooperation of the embodiments of the present application, and the principle of solving problems of the storage medium is similar to that of the method, the implementation of the storage medium can refer to the implementation process of the above-mentioned method embodiments, and the repeated parts will not be described again.

[0181] Embodiment 4

[0182] In some possible implementation manners, various aspects of the method of the embodiments of the present application can also be implemented in the form of a program product, which includes program codes for causing a computer device to execute the steps of the logic reasoning method based on knowledge enhancement and capsule network cooperation according to various exemplary embodiments of the present application described above in the specification when the program product is run on the computer device. Among them, the executable computer program codes or "codes" for executing various embodiments can be written in high-level programming languages such as C, C++, C#, Smalltalk, Java, JavaScript, Visual Basic, Structured Query Language (for example, Transact-SQL), Perl, or in various other programming languages.

[0183] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above-described embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0184] In the description of this specification, the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" mean that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine different embodiments or examples described in this specification and features of different embodiments or examples without contradiction.

[0185] The above embodiments are intended only to illustrate the technical concepts and features of the present invention. Their purpose is to enable those skilled in the art to understand the contents of the present invention and implement them accordingly. They are not intended to limit the scope of protection of the present invention. Any equivalent changes or modifications made based on the essence of the present invention are intended to be covered by the scope of protection of the present invention.

Claims

1. A knowledge-based enhancement and capsule network collaborative logical reasoning method, characterized in that, Comprise the following steps: Construct a public knowledge local database, and locally deploy a vector database and a graph network database; According to the logical reasoning text, a preliminary retrieval is carried out, and the retrieval range is expanded based on the graph network; The logical text, the question and the related background knowledge are input into the large language model to generate the logical reasoning link, and all the contents are integrated to obtain the knowledge enhanced logical reasoning text; According to the knowledge enhanced logical reasoning text, a semantic graph and a connection graph are constructed; The semantic graph and the connection graph are respectively imported into the capsule network, and the dynamic routing algorithm is used to promote the low-level capsule to the high-level capsule to accurately capture the complex association between nodes; The average fusion operation is respectively performed on a plurality of high-level capsules in the double graph to extract the global features of the graph; The global features of the double graph are integrated through a fusion strategy to form the final knowledge text features, and the final option is obtained; The knowledge enhanced logical reasoning text is used to construct a semantic graph and a connection graph, comprising: By combining the original logical text C, question Q, thinking reasoning path G and option answer O, a structure of [CLS]C[SEP]Q[SEP]G||O[SEP] is constructed, which is input into the large language model. The [CLS] feature vector in the obtained multiple candidate answers is mapped through a linear layer, and then the probability distribution of each candidate answer is obtained through a Softmax activation function, which is specifically expressed as: P(O1, O2, O3, O4|CQG); Finally, the gradient backpropagation operation is performed on the model by using the cross-entropy loss function to realize the optimization and update of the model parameters; The large language model constructs a semantic graph and a connection graph according to direct conjunction and punctuation: the context is divided into nodes, and the association between nodes is used as the edge to construct the architecture of the graph. Such association is divided into direct and indirect conjunction, and each node represents a text paragraph connected by logical association. Adopting conjunction and punctuation as two types of connection links, the semantic graph and the connection graph are constructed accordingly. Input the structural framework of [CLS]C[SEP]Q[SEP]G||O[SEP] into a pre-trained large language model to obtain an initial feature vector V of each node i The specific input form is as follows: input=[CLS]+C+[SEP]+Q+[SEP]+G+[SEP]+O+[SEP] V i = RoBERTa_Large(input) In the constructed connection graph and semantic graph, each node contains a plurality of tokens, and the token is represented as follows: The eigenvector corresponding to the Token is: The feature vector corresponding to each node not only includes the semantic content of the node itself, but also includes the position embedding information of the node in the text structure.

2. The logical reasoning method based on knowledge enhancement and capsule network cooperation according to claim 1, characterized in that: The construction of the public knowledge local database and the local deployment of the vector database and the graph network database comprise: Extracting related background knowledge, logical rules and common logical fallacies from existing open source data sets; Using a large model to extract key knowledge from the collected text; wherein the key knowledge includes coarse-grained summary knowledge and entity metadata; The coarse-grained summary knowledge is vectorized, and the vectorized knowledge is stored in the vector database for subsequent knowledge retrieval. construct a graph network according to the extracted entity metadata; wherein nodes in the graph network represent each knowledge document containing knowledge entities in the knowledge document; extract co-occurrence relationships of the knowledge documents from the graph network, and construct edges from the knowledge document to the knowledge document, which represent the association relationships between the entities and the knowledge documents. 3.The knowledge-enhanced and capsule network collaborative logical reasoning method according to claim 1, wherein, The preliminary retrieval according to the logical reasoning text and the extension of the retrieval range based on the graph network include: Perform preliminary retrieval by calculating the similarity between the logical reasoning text vector and the local knowledge document vector, and identify the most relevant knowledge documents; Based on the constructed graph network, the retrieval range is extended: by analyzing the co-occurrence relationships and associations between the preliminary retrieved knowledge text and other knowledge, more relevant background knowledge documents are identified and included to ensure that the extended document set provides more comprehensive background context information.

4. The method of claim 1, wherein, The logical reasoning text, the question and the relevant background knowledge are input into the large language model to generate the logical reasoning link, and all the contents are integrated to obtain the knowledge enhanced logical reasoning text, including: The retrieved relevant knowledge documents, logical reasoning texts and problems are merged to obtain an overall large paragraph I i : I i = concat(d 扩展 ,C i ,Q i ) wherein d 扩展 represents a knowledge document for extended search, C i represents a logical reasoning text, Q i represents a question; The combined whole large paragraph I i is input into a large language model to generate a logical thinking reasoning link G i . The thinking link G i is placed behind the whole large paragraph I i to form the final enhanced logical reasoning text R i : R i = concat(C i ,Q i ,G i ) 5. The method of claim 1, wherein, In order to maintain the sequence relationship of the nodes in the text context, the position embedding technology is introduced, which aims to add position features to the vector representation of each node, so that the model can effectively identify the relative position of different nodes in the text. The specific expression is: n i = s i + PE(s i ) In the formula, n i denotes the node feature after adding the original node and the position encoding, for each enhanced logical reasoning text R i , and a specific option O i The corresponding graph g i , there is the following relationship: g i = (N i , E i ) where E i represents edges connecting nodes N i , E i includes edges of conjunctions and punctuation marks; and the set N i is defined as: N i :{n1,n2,…,m k}.

6. The method of claim 1, wherein, The semantic graph and the connection graph are respectively introduced into the capsule network, and the dynamic routing algorithm is used to promote the low-level capsules to the high-level capsules to accurately capture the complex associations between nodes, including: The node features of the semantic graph and the connection graph are input into the capsule network, and through the process of iterating multiple dynamic routing, the low-level capsules are approximated to the high-level capsules to obtain K short-term information vector features. K is a preset hyperparameter, and short-term local text information in each graph is extracted; The dynamic routing mechanism in the capsule network adaptively adjusts the path of information transmission according to the input.

7. The method of claim 1, wherein, The average fusion operation is performed on multiple high-level capsules in the double graphs respectively to extract the global features of the graphs; Then, the global features of the double graphs are integrated through a fusion strategy to form the final knowledge text features, and the final options are obtained, including: By averaging the features of all high-level capsules in each image ​ The original question and the feature vector of each option are coupled by using an interactive attention component to more effectively grasp the logical text information and logical structure. The original question and the feature vector of each option are coupled by using an interactive attention component to more effectively grasp the logical text information and logical structure. An interactive attention component is used to measure the similarity between the global graph vector representation and each option, question, and this similarity is considered as a weight, assigned to the vector representation among; After the interactive attention mechanism component is completed, in order to improve the performance of the model, the feature vector Option representation V option And question representation V' question Coupling and inputting them into a fully connected neural network to obtain a final feature representation; according to the feature representation, calculating the probability distribution of each candidate item, and selecting the candidate item corresponding to the maximum probability value as the prediction result.

8. An electronic device, comprising: The electronic device includes a processor and a memory, and the memory stores at least one instruction, at least one program, a code set or an instruction set. The at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method of any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, at least one program, a code set or an instruction set. The at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method of any one of claims 1-7.

Citation Information

Patent Citations

  • Description knowledge graph, text graph coding model and graph-based pre-training method

    CN117252256A

  • Machine reading understanding method based on cross-graph collaborative modeling

    CN117764085A