A graph neural network and logic fusion method for premise selection
By expressing the first-order logic formula as a logic formula graph and combining it with the GraphSAGE model and through-estimation technology, the shortcomings of graph neural networks in utilizing logical information in the existing technology are solved, and more efficient premise selection and automatic reasoning performance are achieved.
Patent Information
- Application Number
- CN202411443001.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-10-16
AI Technical Summary
The existing prerequisite selection method based on graph neural networks has shortcomings in utilizing logical information, mainly because the cross-entropy loss ignores logical information, making it difficult for the model to effectively utilize logical rules and constraints during training and inference.
Proposed a method for the fusion of neural networks and logic with prerequisites. By expressing first -order logic formula as a logical formula, and using the Graphsage model for information transmission and aggregation, the logical formula map was finally transformed into Tit syllable. At the same time, it is used to use the directly -through estimation technology to improve the loss code, calculate the losses of the logical formula, and combine it with cross -entropy losses to guide model training.
Through logical fusion methods, the model can better use logic information, improve the accuracy and efficiency of the prerequisite selection, and significantly improve the performance of the neural network in automatic reasoning tasks.
Smart Images

Figure CN118966273B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of automatic reasoning technology, and in particular to a graph neural network and logic fusion method for premise selection. Background Art
[0002] Automated Theorem Proving (ATP) is one of the important branches in the interdisciplinary research field of computer science and mathematical logic, and is also one of the core components of artificial intelligence. Its focus is on developing algorithms and techniques that enable computers to automatically derive new conclusions from a given set of premises. As one of the core contents of automated reasoning, the automated theorem prover (ATP) aims to develop technologies for generating computer programs to enable computers to automatically reason and solve problems. ATP receives premises and conclusions in the form of first-order logic as input, and automatically generates conclusions from the premises. ATP covers a variety of reasoning forms, including logical reasoning, mathematical reasoning, and inductive reasoning. Through automated reasoning, computers can draw new conclusions from known facts or premises or verify whether a given hypothesis or theorem is valid.
[0003] The efficiency of ATP mainly depends on the inference rules and search strategies. Traditional ATP can effectively prove conjectures in small-scale axiom sets, that is, give a deductive sequence from the axiom set to the conjecture clause set. However, in large-scale axiom sets, the search space of ATP will show exponential growth, causing the computer resources to be quickly exhausted. In fact, the formalization of practical problems usually contains millions of axioms. For ATP, it is extremely difficult to handle large-scale axiom sets (the axiom set used to prove most conclusions only requires dozens of axioms). In this case, premise selection is one of the effective ways to solve large theoretical problems.
[0004] In the early stage of ATP research, scholars transformed various mathematical problems into first-order logic formulas and used ATP for automatic logical deduction. Many mathematical problems have been successfully transformed and proved by ATP, which has promoted the development of ATP technology. However, in the face of increasingly large-scale and complex challenges, ATP needs to deal with large-scale problems containing tens of millions of premises; only a small part of them are the conclusions required for proof. In the case of a large number of useless premises, the search space is too large, which will significantly reduce the efficiency of deduction. To meet this challenge, premise selection is required in the preprocessing stage: that is, selecting premises with high relevance to the given conjecture deduction sequence or that may appear in the proof process from these large-scale premise sets; this is equivalent to converting large-scale problems into small and medium-scale problems to reduce processing complexity and speed up the deduction process. It is worth noting that premise selection will not affect the subsequent deduction process of ATP. Although traditional logic methods have difficulties in dealing with complex problems, graph neural networks, as an effective tool, can make full use of logical information and solve this challenge; it can capture complex relationships between data and convert them into graph structures. This approach enables graph neural networks to learn complex relationships and patterns between data, and better handle complex logical problems caused by large-scale premise sets under huge amounts of data, which coincides with the goal of premise selection. Therefore, the combination of graph neural networks and logic can more effectively understand and process complex logical relationships, enhance the inference ability of graph neural networks, and thus improve their performance.
[0005] With the continuous development of machine learning and ATP, many large-scale problems are transformed into first-order logic formulas. Many of these large-scale premise sets are useless and redundant for the reasoning process of the conclusions, and useful premises only occupy a small part of them. Therefore, premise selection for these huge premise sets can effectively improve efficiency. In the process of ATP development, the automatic reasoning process of many problem conclusions has been saved in the knowledge base. The selected premises in these proof processes and the problem conclusions proved by these premises have greatly promoted the development of premise selection methods, which provides rich experience for premise selection in the ATP preprocessing stage. There are now many algorithms with low complexity and stability, such as the naive Bayes method and the k-nearest neighbor algorithm in machine learning algorithms; and convolutional neural networks and graph neural networks (Graph Neural Network, GNN) in deep learning algorithms.
[0006] However, although the existing premise selection methods based on graph neural networks can improve the ability of premise selection classification to a certain extent, they still have some shortcomings:
[0007] 1) The current mainstream way of guiding graph neural networks to reduce losses is mainly through cross-entropy loss, which ignores the logical information of first-order logic formulas and thus cannot use logic well to guide model training and learning direction.
[0008] 2) Since these graph neural networks basically use cross entropy loss, they cannot make good use of logical information to constrain the neural network at this location. Summary of the invention
[0009] The content of the present invention is to provide a graph neural network and logic fusion method for premise selection, which can overcome certain or some defects of the prior art.
[0010] A graph neural network and logic fusion method for premise selection according to the present invention comprises the following steps:
[0011] Step 1, express the first-order logic formula as a logic formula diagram;
[0012] Step 2: Use the graph neural network logic fusion model to perform information transmission, information aggregation and pooling, and finally convert the logic formula graph into a graph feature representation;
[0013] Step 3: Improve the loss coding based on the logical formula of the direct estimation;
[0014] 3.1) Encode the pre-input conjunction normal form and use the straight-through estimator to encode the C matrix, v vector and g vector as the loss function; Encode the conjunction normal form to parse the clause list first: extract information by passing each clause string to the clause class and generate a mapping from atoms to indices;
[0015] 3.2) Construct a matrix representation C of the logic formula from these clauses; then simplify and verify the clauses: simplify the clauses by comparing the affirmative and negative forms of the atoms in the clauses through the resolution principle. After completing the C matrix, the constructor prints the mapping from atoms to indices and the dimensions of the matrix C to verify the correctness of the matrix construction;
[0016] 3.3) Calculate the logistic formula loss through the C matrix, v vector and g vector;
[0017] Step 4: Establish a premise selection model based on straight-through estimation improvement loss, and use a binary classifier combined with logic formula graph, graph feature representation and logic formula loss for classification and prediction.
[0018] Preferably, in step 1, a logic formula graph is constructed based on a mixed structure of parameter relations. When constructing, edges are added between the parameter nodes belonging to the predicate to connect the parameters.
[0019] Preferably, in step 2, the polymerization operation is specifically:
[0020] The graph neural network logic fusion model is GraphSAGE. The information aggregation process is to update the node information based on the information of its own node and its neighboring nodes through aggregation methods, including LSTM and Pooling. GraphSAGE first aggregates the features of neighboring nodes, and then concatenates them with the features of neighboring nodes, that is, concatenates the vectors. The formula is as follows:
[0021]
[0022] Among them, AGGREGATE k Represents an aggregate function, represents the vector of node v at the kth iteration, and N(v) represents the set of all neighbor nodes of node v;
[0023] In order to obtain stronger feature expression, add a nonlinear activation function σ:
[0024]
[0025] Among them, W (k) represents the learnable weight matrix at the kth iteration, u is a node in the neighbor node set N(v), and CONCAT represents the concatenation function;
[0026] After each iteration, each node is normalized to obtain the overall GraphSAGE aggregation.
[0027] Preferably, in step 2, the pooling operation is specifically: combining self-attention pooling, global average pooling and global maximum pooling to generate a final logic formula graph embedding vector, that is, a graph feature representation.
[0028] Preferably, in step 3, the logic formula is obtained by formalizing the logic properties, specifically:
[0029] a) Give the domain and symbols of predicate logic in the dictionary, including predicate symbols, function symbols, and constant symbols;
[0030] b) Propose logical rules suitable for premise selection, considering logical formulas constrained by universal quantifiers;
[0031] c) The logical formulas in predicate logic are transformed into propositions and expressed in the form of a set of clauses, that is, each clause represents a logical rule.
[0032] Preferably, in step 3.1), the direct estimator first performs a binarization process, calculates the gradient clipping operation, then saves the value for future use in the forward propagation, and implements a custom gradient calculation in the backward propagation to clip the gradient, and finally checks and returns the corresponding integer tensor;
[0033] Deterministic binarization:
[0034]
[0035] in, is the binary value of the lth neuron x in the i-th layer;
[0036] Forward propagation process direct function:
[0037]
[0038] in, is the binary value of the lth neuron x in the i-th layer, The initial value of the lth neuron x in the i-th layer, and clip is the restriction function in Python.
[0039] Preferably, in step 3.3), specifically:
[0040] 3.3.1) Parse clause list;
[0041] When initialized, it receives an optional DIMACS format string or a clause list; if no DIMACS format string is provided, it processes the clause list;
[0042] 3.3.2) Calculate the satisfaction of the clause;
[0043] First, according to the values of C, v, and g, C is calculated through matrix operations i The truth value of each literal in each clause in C i Refers to the i-th column in C; then, for each clause, count the number of unsatisfied clauses by multiplying the literal values in each clause and summing them;
[0044] 3.3.3) Calculate the loss;
[0045] For clauses that cannot be applied through unit propagation, a loss value L is calculated unup , for the clauses applied through unit propagation, another loss value L is calculated up , and finally add the regularization term L2. The sum of these three is the logic formula loss of a single premise. The average of the logic formula losses of the correctly classified n premises is the final logic formula loss. L unup With L up The calculation method is as follows:
[0046] (i) For clauses that cannot be applied through unit propagation: For each clause, we first need to determine whether the clause is true, that is, whether there is at least one atomic proposition in the clause that is true. If the clause is satisfiable, that is, the truth value of the clause is true, then we need to calculate the loss L of the clause.sat ;
[0047] Specifically, the truth value of each atomic proposition in the clause is compared with the expected value, and then the difference between the two is calculated. The expected value used is represented by the node features output by the neural network; finally, the loss values of all parts that meet the conditions are accumulated, and then the average value is calculated and recorded as L unupsat ; At the same time, the losses of the unsatisfied parts of the clauses are accumulated, the average is calculated and recorded as L unupunsat ;
[0048] L sat The calculation formula is as follows:
[0049]
[0050] Similarly, if the truth value of the clause is false, then the loss L of the clause needs to be calculated unsat :
[0051]
[0052] Finally, the total loss L of the clauses that cannot be applied through unit propagation is obtained unup :
[0053] L unup =L sat +L unsat (3-4)
[0054] (ii) For the loss of clauses to which unit propagation can be applied: that is, clauses with undetermined variables, we need to count the number of undetermined variables in each clause, and then sum the number of undetermined variables in all satisfied clauses to find the average value L upsat ; The number of undetermined variables in all unsatisfied clauses is accumulated and the average value L is calculated upunsat ; Finally, calculate L up :
[0055]
[0056] In this way, L up It can be used to measure the accuracy of the model in processing clauses;
[0057] L g =C⊙g(3-6)
[0058] L v =1 (1) (C)⊙v+1 (-1) (C)⊙(1-v) (3-7)
[0059] deduce=1 (1)(sum(C⊙C)-sum(1 (-1) (L f )) (3-8)
[0060] upsat=prod(1-L v ) (3-9)
[0061] keep=sum(1 (1) (L v )⊙(1-L v )+1 (0) (L v )⊙L v )(3-10)
[0062] L updat =deduce⊙unsat (3-11)
[0063] L unupunsat =avg((1 (1) (unsat)⊙unsat) (3-12)
[0064] L unupsat =avg((1 (0) (unsat)⊙keep) (3-13)
[0065] L cnf (C,v,g)=L up +L unup +L2(3-14)
[0066] Among them, L2 is a regularization term, which is calculated by multiplying the square of the L2 norm of the C matrix by the regularization coefficient; the loss function L cnf Characterize the properties of logical formulas to guide the training of graph neural networks so that their prediction results in premise selection tasks meet logical constraints; L g It is a form of non-integer containing logical rule g and conclusion. f It refers to the logical representation of the logical rule, prod represents the product function of the elements, avg represents the average function of the elements, sum represents the sum function, ⊙ represents the product of the matrix by elements, L v represents a vector containing premises and 0 elements and a vector containing conclusions, deduce represents the set of clauses that can be deduced by the logical rule g, upsat represents the set of clauses that cannot be satisfied by v, and keep represents the predicted value of v in each clause in the actual data set. Through the above formal expression, the degree of satisfaction of the logical rules during training can be measured, that is, when the loss function is 0, the model satisfies the proposed logical rules.
[0067] Preferably, in step 4, specifically:
[0068] In the GraphSAGE graph neural network logic fusion model, a binary classifier is used for classification and prediction; the input of the binary classifier is the graph vector pair of the premise and conclusion of the model output, that is, l prem , l conj ; The binary classifier uses the classification function F class To predict whether the premise is useful in proving the conclusion, we can get the classification prediction score z in the interval [0,1]:
[0069] z=F class ([l prem ,l conj ])(3-15)
[0070] In order to highlight the classification ability of the model, the binary classifier used is a two-layer MLPs, which has the following form:
[0071] F class (x) = D2(ReLU(D1(x)+b1))+b2(3-16)
[0072] Among them, D1 and D2 are learnable weight matrices; b1 and b2 are learnable parameter vectors;
[0073] Then the obtained z is normalized using the softmax function to obtain the classification probability
[0074]
[0075] in, for The elements in z i is the i-th element of z; z k is the kth element of z;
[0076] The total loss is calculated as:
[0077]
[0078] Cross Entropy Loss The calculation method is:
[0079]
[0080] Among them, y i Represents the actual label of the data.
[0081] The beneficial effects of the present invention are as follows:
[0082] (1) In order to solve the problem of integrating logical properties into loss functions, this paper proposes a general and widely applicable logic fusion method, and introduces the overall process of graph neural network and logic fusion using the GraphSAGE network model. Compared with the traditional cross entropy loss, this method additionally uses L unup , L up The logical formula loss is calculated by summing the logical formula loss and the cross entropy loss to get the final total loss. The weights can be adjusted independently. Adjusting the weight of the logical formula loss to zero is the original model.
[0083] (2) In order to solve the problem of difficulty in encoding logical properties, the present invention uses the direct estimation technology to encode the logical formula, calculates the loss of the clauses that cannot be propagated and the loss of the clauses that can be propagated respectively, and considers the satisfiable part and the unsatisfied part of the clause and the node characteristics of the neural network output as the expected value to calculate the loss. Finally, L2 regularization is added to stabilize the learning process.
[0084] (3) In order to solve the problem of difficulty in maintaining logical properties in learning models, the present invention incorporates logical formula loss into graph neural networks to achieve the embedding of logical rules. cnf and L bound Covers the neural network output. L cnf Encodes logical constraints, while L bound Prevent neural network outputs from growing too large. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] Figure 1 It is a flow chart of a graph neural network and logic fusion method for premise selection in an embodiment;
[0086] Figure 2 A directed graph is constructed based on a predicate parameter relationship hybrid structure in an embodiment. DETAILED DESCRIPTION
[0087] In order to further understand the content of the present invention, the present invention is described in detail in conjunction with the accompanying drawings and embodiments. It should be understood that the embodiments are only for explaining the present invention and are not intended to limit it.
[0088] Example
[0089] like Figure 1 As shown, this embodiment provides a graph neural network and logic fusion method for premise selection, which specifically includes the following steps:
[0090] Step 1: Represent the first-order logic formula as a logic formula (directed) graph. This embodiment proposes a method for constructing a logic formula directed graph based on a parameter relationship hybrid structure. Since there must be a certain relationship between the parameters of the predicates of the first-order predicate logic, that is, the relationship of the predicates, when constructing the directed graph, edges are added between the parameter nodes belonging to the predicates to connect these parameters.
[0091] First-order logic formula F, where A1, A2, ..., A n For all logical symbols in F in order, its directed graph representation G based on the order structure F =(V F , E F ) is recursively defined as:
[0092] (1)V F =V F ∪{A k}, E F =E F ∪{ k-1 ,A k >}, where k loops from 2 to n, initializing V F ={A1},
[0093] (2) If A k is a constant symbol, and it is a parameter of a function or predicate, belonging to the function symbol A i (i<=k), then E F =E F ∪{ k ,A i >}.
[0094] (3) If A k is a variable symbol, and it is a parameter of a function or predicate, belonging to the function symbol A i (i<=k), then E F =E F ∪{ k ,A i >}; and if he is a quantifier node A j (j<=k) quantized variable node, then E F =E F ∪{ k ,A j >}.
[0095] (4) If A k Function symbol node (function node or predicate node), its parameter node is A 11 , A 12 , …, A 1n ,So GF =(V F , E F ).
[0096] (5) If parameter node A 11 , A 12 , …, A 1n belongs to the predicate node, then G F =(V F , E F ). Where i≠j.
[0097] (6) If Then E F =E F ∪{ k ,A k+1 >}, G F =(V F , E F ).
[0098] (7) If A k =⊙, And A k =H(A k-1 )⊙H(A k+1 ) Then E F =E F ∪{ <H(A k-1 ),A k >, k ,H(A k+1 )>},G F =(V F , E F ). Where H(A) is the outermost predicate symbol of the logic symbol A.
[0099] This method is based on the existence of a certain relationship between the parameter nodes belonging to the same predicate, so a bidirectional edge is constructed between these parameter nodes with a certain relationship to transmit information. Figure 2 This is an example of converting the first-order logic formula Construct a directed graph based on the predicate parameter relation hybrid structure, where: represents a universal quantifier, X and Y represent variable symbols, P and Q represent predicate symbols, f and g represent function symbols, and a represents a constant symbol. Intuitively, it means that there are two predicates P and Q, and there is a certain relationship between their parameter nodes. The relationship between a and f satisfies the relationship of predicate P, and the relationship between f and g satisfies the relationship of predicate Q.
[0100] The algorithm for constructing directed graphs based on the hybrid structure of predicate parameter relations is based on the algorithm for constructing directed graphs based on the logic formula sequence and branch hybrid structure. Considering that the parameters of the predicate must have the predicate relationship, bidirectional edges between the parameters are added to transmit information between the parameters.
[0101] Step 2: Use the graph neural network logic fusion model to perform information transmission, information aggregation and pooling, and finally transform the logic formula graph into a graph feature representation. The main process includes state vector initialization, information aggregation, information propagation, graph aggregation and other steps.
[0102] The process of initializing the graph node vector is as follows: for the input formula graph G = (V, E), each node v∈V on the graph will be assigned an initial feature vector x v . Then the initial feature vector x of node v is v By initial embedding function F V Embedded as a node state vector with fixed dimension Among them, the initial embedding function F V For the lookup table, return the embedding of the fixed dictionary. Node state vector is the output dimension.
[0103] This logic fusion method uses additional conjunction normal form input, logic formula encoding and straight-through estimator technology, and does not design the optimization of a specific model, so the applicability and scalability of this method are very high, and it can be used in conjunction with the optimization of the model itself in other papers or the latest research. Below, the graphSAGE model is used as an example to specifically illustrate the pooling and aggregation process of the graph neural network using this logic fusion method.
[0104] For a directed acyclic graph DAG, the directed adjacency matrix A∈(0,1) of N nodes is N*N Through the word2vec method, the initial features of the node are converted into distributed features X∈R N*d , where d is a hyperparameter and is the dimension of the node’s feature vector.
[0105] The addition of new nodes will definitely change the representation of the original nodes. Therefore, we no longer get a fixed representation for each node but directly learn a node representation method (GraphSAGE). GraphSAGE does not try to learn the embeddings of all nodes on a graph, but learns a mapping that generates embeddings for each node. SAGE stands for Sample and Aggregate. Instead of training a separate embedding vector for each vertex, it trains a set of aggregator functions that learn how to aggregate feature information from the local neighborhood of a vertex. Each aggregation function aggregates information from different hops or different search depths of a vertex. When testing or inferring, use the trained system to generate graph embeddings for completely unseen vertices through the learned aggregation function.
[0106] Each node in the Graph can have its own feature vector, which is obtained by the X node features. Now assume that all feature vectors of each node have the same size. One layer of GraphSAGE can run k iterations. Therefore, every k iterations, each node has a node representation h. Because each node can be approximately represented by its neighbors, the embedding of node A can be represented by some combination of the embedding vectors of its neighboring nodes. After one round of the GraphSAGE algorithm, a new representation of node A can be obtained. All nodes in the original graph follow the same process. At the same time, the logical constraints incorporated are also logical rule embeddings for two adjacent nodes, so that each node is both approximately represented by its neighbors and logically constrained by its neighbors, which can contain more logical information and is easier to understand and process.
[0107] The information aggregation process of GraphSAGE is to update its own node information through aggregation methods based on the information of its own node and its neighboring nodes. The aggregation methods include LSTM and Pooling. GraphSAGE first aggregates the features of neighboring nodes and then concatenates them with the features of the node, so that the original features of the node are retained to distinguish the nodes. The formula is as follows:
[0108]
[0109] Among them, AGGREGATE k Represents an aggregate function, represents the vector of node v at the kth iteration, and N(v) represents the set of all neighbor nodes of node v;
[0110] In order to obtain stronger feature expression, add a nonlinear activation function σ:
[0111]
[0112] Among them, W (k) represents the learnable weight matrix at the kth iteration, u is a node in the neighbor node set N(v), and CONCAT represents the concatenation function.
[0113] After each iteration, each node is normalized to obtain the overall GraphSAGE aggregation;
[0114] The information transmission process is: using the total information from the balance node and the current state vector of the node Update node vector In the kth iteration, the state vector of node v is updated to Among them, F is the node information transfer function, which is generally designed as a simple single-layer multi-layer perceptron.
[0115] The pooling process is as follows:
[0116] Graph pooling is divided into two categories, namely global pooling and hierarchical pooling. Global pooling considers the characteristics of the graph and performs a pooling operation on all nodes on the graph. Hierarchical pooling considers the topological structure of the graph and performs a certain number of pooling on all nodes on the graph. Each pooling reduces the number of nodes on the graph until the final graph embedding vector is generated. In order to retain the characteristics of global pooling and hierarchical pooling, this embodiment combines self-attention pooling, global average pooling and global maximum pooling to generate the final formula graph embedding vector.
[0117] This embodiment first calculates the self-attention scores Z and Z′ of the bidirectional logic formula graph nodes:
[0118]
[0119]
[0120] Among them, Z is the node self-attention score based on the forward logic formula graph, Z rev is the node self-attention score based on the reverse logic formula graph, is the adjacency matrix containing self-loops, Θ att It is the only trainable parameter in SAGPool.
[0121] This embodiment sorts the nodes in descending order according to the bidirectional self-attention score and selects a certain proportion of nodes to reduce the size of the graph. Then the node features and adjacency matrix are transformed accordingly to generate a new node representation and
[0122]
[0123] in, for The new feature matrix is rearranged according to the index, and A out is the node feature matrix and adjacency matrix corresponding to the pooling, and A out_rev corresponds to the reverse logic formula diagram, Z mask and Z mask_rev is the index transformation matrix.
[0124] This embodiment represents the node and Perform global average pooling (AvgPool) and global maximum pooling (MaxPool) respectively. The final formula graph embedding vector h G for and Do the concatenation of two global poolings:
[0125]
[0126] Step 3: Improve the loss coding based on the logical formula of the direct estimation.
[0127] 3.1) Encode the pre-input conjunction normal form and use the straight-through estimator to encode the C matrix, v vector and g vector as the loss function; Encode the conjunction normal form first parses the clause list: extract information by passing each clause string to the clause class and generate a mapping from atoms to indices.
[0128] 3.2) Construct a matrix representation C of the logical formula from these clauses; then simplify and verify the clauses: simplify the clauses by comparing the affirmative and negative forms of the atoms in the clauses through the resolution principle. After completing the C matrix, the constructor prints the mapping from atoms to indices and the dimensions of the matrix C to verify the correctness of the matrix construction.
[0129] 3.3) Calculate the logistic formula loss through the C matrix, v vector and g vector.
[0130] The straight-through estimator is a technique for solving the problem of gradient estimation for non-differentiable operations in deep learning. Its main idea is to use a binarized function in the forward propagation and replace its gradient with the gradient of a meaningful, different variable function in the backward propagation. In deep learning models, some operations such as thresholding (ReLU), sorting, discretization, etc. are non-differentiable, which means that they have no derivatives, so the gradient cannot be calculated during the back propagation process. This will hinder the learning process of the model because the gradient is the key factor guiding the model learning.
[0131] This is particularly useful for models that rely on non-differentiable operations, such as binary neural networks. In these models, the weights are constrained to be between -1 and 1, so their gradient calculations involve non-differentiable operations. Using a straight-through estimator can make these models easier to train, thereby improving model performance.
[0132] Usually, there are two quantization modes for binarization functions: deterministic quantization and random quantization. In this embodiment, deterministic quantization is used, and the straight-through estimator first performs the binarization process, calculates the gradient clipping operation, and then saves the value for backup in the forward propagation, and implements the custom gradient calculation in the back propagation to clip the gradient, and finally checks and returns the corresponding integer tensor.
[0133] Deterministic binarization:
[0134]
[0135] in, is the binary value of the lth neuron x in the i-th layer;
[0136] Forward propagation process direct function:
[0137]
[0138] in, is the binary value of the lth neuron x in the i-th layer, The initial value of the lth neuron x in the i-th layer, and clip is the restriction function in Python.
[0139] The main idea of the straight-through estimator is to use a binary function in the forward propagation and replace its gradient with a meaningful gradient of a different variable function in the backward propagation. However, the straight-through estimator alone cannot achieve constrained learning. A systematic method is also needed to encode logical constraints into a loss function. This method is logical formula encoding, which implements the logical formula (conjunction normal form) representation of Boolean logic and provides a method to convert logical clauses into tensor representations. Logical rules are mainly expressed in the following forms: logical symbols, logical expressions, logical relations, etc. Graph neural networks also face some challenges when processing logical rules. It usually takes up a lot of resources when processing large-scale graph data, and its training and reasoning process may become very time-consuming. The connections between nodes in the graph are likely to be sparse, resulting in insufficient information transfer. Therefore, logical embedding is an effective method.
[0140] The usage scenario of this embodiment is premise selection, which includes 2078 questions and a large premise set. Due to the great differences between different questions and their proof processes and the complexity of large premise sets, it is almost impossible to cover all the problem proofs by inputting a logical formula. Therefore, this embodiment pre-inputs a conjunction normal form composed of multiple conjunction normal forms and logically constrains the graph neural network through direct estimation, and gives its rationality for the premise selection task in the calculation process.
[0141] The specific process of calculating the loss of the logical formula is as follows:
[0142] 3.3.1) Parse clause list;
[0143] During initialization, it receives an optional DIMACS format string or a clause list; if no DIMACS format string is provided, it processes the clause list, where DIMACS is a general representation of the conjunction normal form of propositional logic; the calculation of the logic formula loss receives three parameters "C", "v", and "g". "C" is a matrix of logic formulas constructed from multiple pre-input clauses, containing a two-dimensional vector matrix C1, C2, ..., C constructed from n conjunction normal forms. n , where the two-dimensional vector matrix C i The rows represent clauses, the columns represent atoms, and the shape is M*N. i The value in is 1 or -1, indicating whether the atom is affirmative or negative in the clause, respectively; "v" is a vector of length n, representing the truth value assignment of the n premises after the output of the binarized neural network; "g" is a vector of length n, representing the truth value assignment of the n premises determined only by the labels.
[0144] 3.3.2) Calculate the satisfaction of the clause;
[0145] First, according to the values of C, v, and g, C is calculated through matrix operations i The truth value of each literal in each clause in C i Refers to the i-th column in C; then, for each clause, count the number of clauses that are not satisfied by multiplying the literal values in each clause (because in logic, a clause satisfies if and only if at least one literal is true) and summing them.
[0146] 3.3.3) Calculate the loss;
[0147] For clauses that cannot be applied via unit propagation, a loss value L is calculated unup , for the clauses applied through unit propagation, another loss value L is calculated up, and finally add the regularization term L2. The sum of these three is the logic formula loss of a single premise. The average of the logic formula losses of the correctly classified n premises is the final logic formula loss. This will introduce the logical relationship between premises. There are dependencies and differences between different premises, which has a certain promoting effect on the premise selection task. L unup With L up The calculation method is as follows:
[0148] (i) For clauses that cannot be applied through unit propagation: For each clause, we first need to determine whether the clause is true, that is, whether there is at least one atomic proposition in the clause that is true. If the clause is satisfiable, that is, the truth value of the clause is true, then we need to calculate the loss L of the clause. sat ;
[0149] Specifically, the truth value of each atomic proposition in the clause is compared with the expected value, and then the difference between the two is calculated. The expected value used is represented by the node features output by the neural network; finally, the loss values of all parts that meet the conditions are accumulated, and then the average value is calculated and recorded as L unupsat ; At the same time, the losses of the unsatisfied parts of the clauses are accumulated, the average is calculated and recorded as L unupunsat ;
[0150] L sat The calculation formula is as follows:
[0151]
[0152] Similarly, if the truth value of the clause is false, then the loss L of the clause needs to be calculated unsat :
[0153]
[0154] Finally, the total loss L of the clauses that cannot be applied through unit propagation is obtained unup :
[0155] L unup =L sat +L unsat (3-4)
[0156] (ii) For the loss of clauses to which unit propagation can be applied: that is, clauses with undetermined variables, we need to count the number of undetermined variables in each clause, and then sum the number of undetermined variables in all satisfied clauses to find the average value L upsat ; The number of undetermined variables in all unsatisfied clauses is accumulated and the average value L is calculated upunsat ; Finally, calculate L up :
[0157]
[0158] In this way, L up It can be used to measure the accuracy of the model in processing clauses;
[0159] L g =C⊙g(3-6)
[0160] L v =1 (1) (C)⊙v+1 (-1) (C)⊙(1-v)(3-7)
[0161] deduce=1 (1) (sum(C⊙C)-sum(1 (-1) (L f )) (3-8)
[0162] upsat=prod(1-L v ) (3-9)
[0163] keep=sum(1 (1) (L v )⊙(1-L v )+1 (0) (L v )⊙L v )(3-10)
[0164] L upsat =deduce⊙unsat(3-11)
[0165] L unupunsat =avg((1 (1) (unsat)⊙unsat) (3-12)
[0166] L unupsat =avg((1 (0) (unsat)⊙keep) (3-13)
[0167] L cnf (C,v,g)=L up +L unup +L2 (3-14)
[0168] Among them, L2 is a regularization term, which is calculated by multiplying the square of the L2 norm of the C matrix by the regularization coefficient; the loss function L cnf Characterize the properties of logical formulas to guide the training of graph neural networks so that their prediction results in premise selection tasks meet logical constraints; L g It is a form of non-integer containing logical rule g and conclusion. fIt refers to the logical representation of the logical rule, prod represents the product function of the elements, avg represents the average function of the elements, sum represents the sum function, ⊙ represents the product of the matrix by elements, L v represents a vector containing premises and 0 elements and a vector containing conclusions, deduce represents the set of clauses that can be deduced by the logical rule g, upsat represents the set of clauses that cannot be satisfied by v, and keep represents the predicted value of v in each clause in the actual data set. Through the above formal expression, the degree of satisfaction of the logical rules during training can be measured, that is, when the loss function is 0, the model satisfies the proposed logical rules.
[0169] In step 3, the logical formula is formalized according to the logical properties, specifically:
[0170] This embodiment proposes a lexicon semantics method to construct a formal method for premise selection, and the steps are as follows:
[0171] a) Give the domain and symbols of predicate logic in the dictionary, including predicate symbols, function symbols, and constant symbols;
[0172] b) Propose logical rules suitable for premise selection, mainly considering logical formulas constrained by universal quantifiers;
[0173] c) The logical formulas in predicate logic are transformed into propositions and expressed in the form of a set of clauses, that is, each clause represents a logical rule.
[0174] If the logical rule is The meaning is: if premise i2 is useful for conclusion i1, and predicate P and its individual constant c both appear in the conclusion, then if predicate P appears in the premise, then individual constant c must also appear in the premise or there exists individual variable X and corresponding universal quantifier that can be replaced. Furthermore, each different predicate of the logic formula can be regarded as a different atomic proposition variable, which becomes the corresponding propositional logic formula.
[0175] Step 4: Establish a premise selection model based on straight-through estimation improvement loss, and use a binary classifier combined with logic formula graph, graph feature representation and logic formula loss for classification and prediction.
[0176] The goal of premise selection is to reduce the search space as much as possible, thereby reducing the scale of the proof problem. Premise selection is considered a classification or sorting task, which evaluates and sorts the correlation between the conclusion and the premises in the premise set corresponding to the conclusion, and then selects the premise with a higher ranking, that is, the premise with higher correlation. In this way, an effective reasoning path can be found more quickly during the proof process.
[0177] In the GraphSAGE graph neural network logic fusion model, a binary classifier is used for classification and prediction; the input of the binary classifier is the graph vector pair of the premise and conclusion of the model output, that is, l prem , l conj ; The binary classifier uses the classification function F class To predict whether the premise is useful in proving the conclusion, we can get the classification prediction score z in the interval [0,1]:
[0178] z=F class ([l prem ,l conj ]) (3-15)
[0179] In order to highlight the classification ability of the model, the binary classifier used is a two-layer MLPs, which has the following form:
[0180] F class (x) = D2(ReLU(D1(x)+b1))+b2(3-16)
[0181] Among them, D1 and D2 are weight matrices that can be learned; b1 and b2 are parameter vectors that can be learned;
[0182] Then the obtained z, that is, the classification prediction score, is normalized using the softmax function to obtain the classification probability
[0183]
[0184] in, for Elements in z i is the i-th element of z; z k is the kth element of z;
[0185] The total loss is calculated as:
[0186]
[0187] Cross Entropy Loss The calculation method is:
[0188]
[0189] Among them, y i Represents the actual label of the data.
[0190] Experimental analysis
[0191] The data involved in this experiment all use the MPTP2078 dataset. Among them, the question bank contains 2078 questions, which are all formalized into first-order logic formulas. A premise set contains a large number of premises, which may be useful or useless for the proof process of the conclusion. There are more useless premises and their distribution is very uneven. Note that a conclusion can be obtained by multiple different proof methods. Therefore, these different proof methods may also contain different premise sets. The premises that appear at least once in the proof process are called useful premises. Each set of data in the dataset is a triple containing conclusion, premise, and label, where the premise corresponds to the conclusion. The label is (0, 1). 1 represents that the premise in the triple is useful for the proof of the corresponding conclusion, and 0 represents useless premise. In order to make the distribution of useful premises and useless premises roughly the same, the K nearest neighbor algorithm is used to sort the useless premises of each conclusion and select useless premises that are equal to the number of positive samples and are at the front as negative samples. Finally, the dataset is randomly divided into training set, validation set and test set in a ratio of 8:1:1, and the corresponding number of samples is 40966, 13990 and 14068. The number of positive samples and negative samples is equal. Table 1 shows the distribution of the number of samples in the dataset.
[0192] Table 1 Distribution table of data set
[0193] Training set Validation set Test Set Number of positive samples 20483 6995 7034 Number of negative samples 20483 6995 7034 Total sample size 40966 13990 14068
[0194] The methods and models involved in this experiment are all implemented in Python, using the torch library and its extension library torch-geometric to implement deep learning algorithms and graph neural network models. The experimental hardware and software environment is: Python3.12, torch2.2.1+cu118, torch-geometric2.5.3, GPU model is NVIDIA GeForce RTX30606G memory, CUDA version 11.8, CPU is Intel i5-11400H.
[0195] The experiment uses the Adam optimizer to train the model and uses the torch StepLR strategy. After a fixed number of rounds (usually 50), the learning rate is reduced to continue training the model. At the same time, the Dropout layer is added to the MLPs to optimize the model. Because the dataset contains a lot of useless premises, this can reduce the model's dependence on unnecessary models in the data and improve the model's generalization ability. All hyperparameters in the experiment are shown in Table 2.
[0196] Table 2 Model training parameter setting table
[0197] parameter set up Node vector dimension d 64,128,256 The number of graph convolutional network layers H 1,2 Training rounds 100 Learning Rate 0.001 Learning rate decay coefficient 0.1 Weight decay coefficient 0.001 Batch size 32 reg regularization coefficient 0.0001
[0198] This model will be trained on the training set. After each round of training iteration, the model will be evaluated on the validation set and the results will be saved. After 100 rounds of training, the cycle with the best effect on the validation set will be selected as the best cycle, and the optimal model under this model will be selected for the final test set for testing.
[0199] Because the number and distribution of positive samples and negative samples used in this experiment are similar, which are 20483, 6995, and 7034. Therefore, this embodiment mainly uses the accuracy index to compare and evaluate the performance of the model. The accuracy can reflect the accuracy of the model in classifying the useful premise and useless premise corresponding to the conclusion:
[0200]
[0201] Among them, TP represents the number of positive samples (useful premises) that are correctly classified and judged; TN represents the number of negative samples (useless premises) that are correctly classified and judged. Total represents the total number of samples.
[0202] While focusing on accuracy, we should also pay attention to the recall rate, precision rate and F1 score of the model, which cannot be ignored in binary classification tasks. The recall rate indicates the classification degree of the model when using the positive sample data:
[0203]
[0204] The precision rate indicates the correct classification rate of the model for these data when the positive samples are classified as the results:
[0205]
[0206] The F1 score represents the harmonic mean of Recall and Precision:
[0207]
[0208] The conclusion is as follows:
[0209] (1) Compared with the current classic graph neural networks, such as: graph convolutional neural network (GCN), graph sampling aggregation neural network (GraphSAGE), Chebyshev neural network (Cheb), graph attention neural network (GAT), simplified graph convolutional neural network (SGC), the model after logical rule fusion has higher performance. As shown in Table 3, the performance of the new model is about 1.3% higher than the highest classic model GCN model, and it is also about 1.47% higher than the original model. In addition, there are certain improvements in F1 score, recall rate, and precision. Table 3 is a data comparison between the logic fusion model and the classic graph neural network model.
[0210] Table 3 Comparison between SAGE logical fusion model and classic model
[0211] Model Accuracy F1 Recall Precision GCN 86.25% 86.08% 85.47% 86.69% GraphSAGE 86.15% 85.92% 85.01% 86.86% Cheb 86.14% 85.94% 85.21% 86.68% GAT 85.38% 85.34% 85.56% 85.11% SGC 85.67% 85.52% 85.12% 85.92% SAGE - Straight-Through Estimator 87.42% 87.20% 86.49% 87.91%
[0212] (2) As a logic embedding method with wide applicability and scalability, this method can also be applied to the remaining classic graph neural networks: graph convolutional neural network (GCN), Chebyshev neural network (Cheb), graph attention neural network (GAT), simplified graph convolutional neural network (SGC). The results of the remaining 4 models under the parameters d = 128, H = 1 and the comparison with the original model are shown in Table 4. The models after the integration of logic rules have a certain improvement compared with the original models. After the GCN logic fusion, the accuracy is improved by 0.59%; after the Cheb logic fusion, the accuracy is improved by 1.5%; after the GAT logic fusion, the accuracy is improved by 1.4%; after the SGC logic fusion, the accuracy is improved by 1.59%.
[0213] Table 4 Comparison between residual logic fusion model and classic model
[0214] Model Accuracy F1 Recall Precision GraphSAGE 86.15% 85.92% 85.01% 86.86% GCN 86.25% 86.08% 85.47% 86.69% GCN-Passthrough Estimator 86.76% 86.62% 86.55% 86.68% Cheb 86.14% 85.94% 85.21% 86.68% Cheb-through estimator 87.44% 87.22% 86.61% 87.85% GAT 85.38% 85.34% 85.56% 85.11% GAT-Through Estimator 86.58% 86.48% 86.70% 86.27% SGC 85.67% 85.52% 85.12% 85.92% SGC - Straight-Through Estimator 87.03% 86.85% 86.52% 87.19%
[0215] The present invention and its embodiments are described schematically above, and the description is not restrictive. The drawings show only one embodiment of the present invention, and the actual structure is not limited thereto. Therefore, if a person skilled in the art is inspired by it and designs a structural method and an embodiment similar to the technical solution without creativity without departing from the purpose of the invention, they shall all fall within the protection scope of the present invention.
Claims
1. A graph neural network and logic fusion method for premise selection, characterized by: The following steps are involved: Step 1, express the first-order logic formula as a logic formula diagram; Step 2: Use the graph neural network logic fusion model to perform information transmission, information aggregation and pooling, and finally convert the logic formula graph into a graph feature representation; Step 3: Improve the loss coding based on the logical formula of the direct estimation; 3.1) Encode the pre-input conjunction normal form and use the straight-through estimator to encode the C matrix, v vector and g vector as the loss function; Encode the conjunction normal form to parse the clause list first: extract information by passing each clause string to the clause class and generate a mapping from atoms to indices; 3.2) Construct a matrix representation C of the logic formula from these clauses; then simplify and verify the clauses: simplify the clauses by comparing the affirmative and negative forms of the atoms in the clauses through the resolution principle. After completing the C matrix, the constructor prints the mapping from atoms to indices and the dimensions of the matrix C to verify the correctness of the matrix construction; 3.3) Calculate the logistic formula loss through the C matrix, v vector and g vector; Step 4: Establish a premise selection model based on straight-through estimation improvement loss, and use a binary classifier combined with logic formula graph, graph feature representation and logic formula loss for classification and prediction.
2. According to claim 1, a graph neural network and logic fusion method for premise selection is characterized by: In step 1, a logic formula graph is constructed based on a parameter relationship hybrid structure. During the construction, edges between the parameter nodes belonging to the predicate are added to connect the parameters.
3. The graph neural network and logic fusion method for premise selection according to claim 2, characterized in that: In step 2, the aggregation operation is specifically as follows: The graph neural network logic fusion model is GraphSAGE. The information aggregation process is to update the node information based on the information of its own node and its neighboring nodes through aggregation methods, including LSTM and Pooling. GraphSAGE first aggregates the features of neighboring nodes, and then concatenates them with the features of neighboring nodes, that is, concatenates the vectors. The formula is as follows: Among them, AGGREGATE k Represents an aggregate function, represents the vector of node v at the kth iteration, and N(v) represents the set of all neighbor nodes of node v; In order to obtain stronger feature expression, add a nonlinear activation function σ: Among them, W (k) represents the learnable weight matrix at the kth iteration, u is a node in the neighbor node set N(v), and CONCAT represents the concatenation function; After each iteration, each node is normalized to obtain the overall GraphSAGE aggregation.
4. The graph neural network and logic fusion method for premise selection according to claim 3 is characterized by: In step 2, the pooling operation is specifically: combining self-attention pooling, global average pooling, and global maximum pooling to generate the final logical formula graph embedding vector, that is, the graph feature representation.
5. The graph neural network and logic fusion method for premise selection according to claim 4 is characterized in that: In step 3, the logical formula is formalized according to the logical properties, specifically: a) Give the domain and symbols of predicate logic in the dictionary, including predicate symbols, function symbols, and constant symbols; b) Propose logical rules suitable for premise selection, considering logical formulas constrained by universal quantifiers; c) The logical formulas in predicate logic are transformed into propositions and expressed in the form of a set of clauses, that is, each clause represents a logical rule.
6. The graph neural network and logic fusion method for premise selection according to claim 5, characterized in that: In step 3.1), the straight-through estimator will first perform the binarization process, calculate the gradient clipping operation, then save the value for future use in the forward propagation, and implement the custom gradient calculation in the back propagation to clip the gradient, and finally check and return the corresponding integer tensor; Deterministic binarization: in, is the binary value of the lth neuron x in the i-th layer; Forward propagation process direct function: in, is the binary value of the lth neuron x in the i-th layer, The initial value of the lth neuron x in the i-th layer, and clip is the restriction function in Python.
7. The graph neural network and logic fusion method for premise selection according to claim 6 is characterized by: In step 3.3), specifically: 3.3.1) Parse clause list; When initialized, it receives an optional DIMACS format string or a clause list; if no DIMACS format string is provided, it processes the clause list; 3.3.2) Calculate the satisfaction of the clause; First, according to the values of C, v, and g, C is calculated through matrix operations i The truth value of each literal in each clause in C i Refers to the i-th column in C; then, for each clause, count the number of unsatisfied clauses by multiplying the literal values in each clause and summing them; 3.3.3) Calculate the loss; For clauses that cannot be applied through unit propagation, a loss value L is calculated unup , for the clauses applied through unit propagation, another loss value L is calculated up , and finally add the regularization term L2. The sum of these three is the logic formula loss of a single premise. The average of the logic formula losses of the correctly classified n premises is the final logic formula loss. L unup With L up The calculation method is as follows: (i) For clauses that cannot be applied through unit propagation: For each clause, we first need to determine whether the clause is true, that is, whether there is at least one atomic proposition in the clause that is true. If the clause is satisfiable, that is, the truth value of the clause is true, then we need to calculate the loss L of the clause. sat ; Specifically, the truth value of each atomic proposition in the clause is compared with the expected value, and then the difference between the two is calculated. The expected value used is represented by the node features output by the neural network; finally, the loss values of all parts that meet the conditions are accumulated, and then the average value is calculated and recorded as L unupsat ; At the same time, the losses of the unsatisfied parts of the clauses are accumulated, the average is calculated and recorded as L unupunsat ; L sat The calculation formula is as follows: Similarly, if the truth value of the clause is false, then the loss L of the clause needs to be calculated unsat : Finally, the total loss L of the clauses that cannot be applied through unit propagation is obtained unup : L unup =L sat +L unsat (3-4) (ii) For the loss of clauses to which unit propagation can be applied: that is, clauses with undetermined variables, we need to count the number of undetermined variables in each clause, and then sum the number of undetermined variables in all satisfied clauses to find the average value L upsat ; The number of undetermined variables in all unsatisfied clauses is accumulated and the average value L is calculated upunsat ; Finally, calculate L up : In this way, L up It can be used to measure the accuracy of the model in processing clauses; L g =C⊙g (3-6) L v =1 (1) (C)⊙v+1 (-1) (C)⊙(1-v) (3-7) deduce=1 (1) (sum(C⊙C)-sum(1 (-1) (L f ))) (3-8) upsat=prod(1-L v ) (3-9) keep=sum(1 (1) (L v )⊙(1-L v )+1 (0) (L v )⊙L v ) (3-10) L unsat =deduce⊙unsat (3-11) L unupunsat =avg(1 (1) (unsat)⊙unsat) (3-12) L unupsat =avg(1 (0) (unsat)⊙keep) (3-13) L cnf (C,v,g)=L up +L unup +L2 (3-14) Among them, L2 is a regularization term, which is calculated by multiplying the square of the L2 norm of the C matrix by the regularization coefficient; the loss function L cnf Characterize the properties of logical formulas to guide the training of graph neural networks so that their prediction results in premise selection tasks meet logical constraints; L g It is a form of non-integer containing logical rule g and conclusion. f It refers to the logical representation of the logical rule, prod represents the product function of the elements, avg represents the average function of the elements, sum represents the sum function, ⊙ represents the product of the matrix by elements, L v represents a vector containing premises and 0 elements and a vector containing conclusions, deduce represents the set of clauses that can be deduced by the logical rule g, upsat represents the set of clauses that cannot be satisfied by v, and keep represents the predicted value of v in each clause in the actual data set. Through the above formal expression, the degree of satisfaction of the logical rules during training can be measured, that is, when the loss function is 0, the model satisfies the proposed logical rules.
8. The graph neural network and logic fusion method for premise selection according to claim 7, characterized in that: In step 4, specifically: In the GraphSAGE graph neural network logic fusion model, a binary classifier is used for classification and prediction; the input of the binary classifier is the graph vector pair of the premise and conclusion of the model output, that is, l prem , l conj ; The binary classifier uses the classification function F class To predict whether the premise is useful in proving the conclusion, we can get the classification prediction score z in the interval [0,1]: z=F class ([l prem ,l conj ]) (3-15) In order to highlight the classification ability of the model, the binary classifier used is a two-layer MLPs, which has the following form: F class (x) = D2(ReLU(D1(x)+b1))+b2(3-16) Among them, D1 and D2 are learnable weight matrices; b1 and b2 are learnable parameter vectors; Then the obtained z is normalized using the softmax function to obtain the classification probability in, for The elements in z i is the i-th element of z; z k is the kth element of z; The total loss is calculated as: Cross Entropy Loss The calculation method is: Among them, y i Represents the actual label of the data.
Citation Information
Patent Citations
Self-supervised graph neural network method based on comparative learning
CN115983351A
Prerequisite selection method based on graph reduction representation and graph neural network
CN117808084A