Formal theorem proof generation method and system based on large model

Through the formal theorem proof generation method based on large models, the proof steps of the formal theorem are directly generated, which solves the problems of large search space and high manual writing cost in the existing technology, and realizes an efficient and automatic theorem proving process.

CN118709756APending Publication Date: 2024-09-27THE QUARTERMASTER RES INST OF THE GENERAL LOGISTICS DEPT OF THE CPLA

Patent Information

Application Number
CN202410836124.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

Existing formal theorem proving methods suffer from the combinatorial explosion problem of the search space, causing non-trivial theorem proofs to exceed the limits of computing power, and manually writing theorem proofs is labor-intensive and costly, and existing automated methods are insufficient when dealing with complex or specific problems. efficient.

Method used

A formal theorem proof generation method based on a large model is adopted. By obtaining training data of formal theorem propositions and mathematical domain knowledge, the large model is pre-trained and parameter adjusted to directly generate formal theorem proof steps and simplify the theorem proof generation process. , reducing the complexity and cost of interactions between predictive models and proof assistants.

Benefits of technology

It greatly reduces the complexity and computational cost of theorem proof, improves hardware utilization, can independently generate and verify proof steps, simplifies the interaction between neural networks and interactive theorem provers, and improves the efficiency and accuracy of automatic theorem proof.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118709756A
    Figure CN118709756A
Patent Text Reader

Abstract

The invention discloses a formalized theorem proof generation method and system based on a large model, and belongs to the technical field of artificial intelligence. The method comprises the following steps: acquiring first training data, wherein the first training data is text data comprising a formalized theorem proposition and all proving steps for proving the formalized theorem proposition; obtaining second training data, wherein the second training data is data including mathematical domain knowledge; pre-training the large model based on the second training data to obtain a pre-trained large model; performing parameter adjustment on the pre-trained large model based on the first training data to obtain an adjusted large model; inputting a formalized theorem proposition of a to-be-generated theorem proving step into the adjusted large model as input data, and generating a formalized theorem proving step of the to-be-generated theorem proving step; according to the method, the complexity of automatically generating the theorem proof can be greatly reduced, and the hardware utilization rate during the model reasoning period can be remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence technology, and in particular relates to a formalized theorem proof generation method and system based on a large model. Background Art

[0002] Formal theorem proving requires a lot of prior knowledge for pattern matching, and its proof process usually relies on computer scientists to translate complex mathematical arguments into a structured formal language and verify it with an interactive theorem prover. However, manually writing theorem proofs is a labor-intensive and costly task. Therefore, recent research has focused on automatic proof synthesis, which can fully automate formal theorem proving. Using heuristics to search the space of possible proofs to try to generate a proof step faces the problem of combinatorial explosion of the search space, resulting in non-trivial theorem proving that exceeds the current computing power limit.

[0003] There are several existing schemes for formal theorem proving.

[0004] (I) Interactive Theorem Prover

[0005] Interactive theorem provers provide a human-computer interactive interface, and give verification results in the process of constructing a specific formalized theorem proof. Users can correct errors or continue to write gaps in the proof under the guidance of error messages and local proof status, respectively. Lean provides a small trusted kernel that relies on type theory. By placing automated tools in a theorem proving framework that supports user interaction, it makes the task of implementing a reference or independent type checker for theorem proofs much simpler. Isabelle provides an interactive environment and uses a high-order logic system that can express most abstract concepts in mathematics and computer science, which can help users verify the correctness of proof scripts. The core of Metamath 87 contains only a small set of basic logical concepts and deduction rules. It uses natural deduction as its proof framework and can verify whether proofs written in the Metamath language are correct. Coq is a powerful theorem prover and program verification system that combines the functions of logic, programming, and proof assistants. It uses a logical foundation of constructive type theory to allow users to write complex proof strategies and extract executable code from proofs. Interactive theorem provers provide a formalism similar to mathematical reasoning, expressing theorems and proofs in high-order logic as high-level strategies. However, users have to manually construct proofs by entering policies into the prover.

[0006] 2. Automated theorem proving method based on “sledgehammer”

[0007] The technology that combines machine learning and translation into automatic reasoning has become an important part of formal proof assistants. This "sledgehammer" technology complements the traditional proof assistant automation achieved by strategies and decision-making processes. The core idea of ​​the "sledgehammer" method is to transform the problem into a search task, that is, to search for proof strategies or theorems that can be applied to the current problem in the existing theorem library. Such methods are often called "sledgehammers" because they are as powerful as a sledgehammer and can try various possible methods to solve the problem. "Sledgehammer" methods, such as CoqHammer and Sledgehammer, repeatedly use a set of pre-computed mathematical facts to try to "hammer" a proof. TacticToe attempts to combine optimized small-scale hammering methods to automatically select appropriate strategies and strategy sequences, and learn from a large number of previous proofs to guide their selection. "Sledgehammer" methods are very useful in formal theorem proving because they can automatically handle many routine or repetitive proof tasks, thereby reducing the burden on human provers. However, this method also has its limitations, such as it may not be effective enough when dealing with very complex or specific problems, and they may not provide the deep understanding and insights that human provers can provide.

[0008] 3. Theorem Proving Method Based on Heuristic Search

[0009] Search-based methods use a predictive model to predict a set of possible next proof steps given some information about a partially written proof, the target theorem being proved, and the current proof status. These methods then use heuristic search to try to compose a proof. They iteratively query the predictive model for possible next steps and use proof assistants to get feedback about these steps and prune infeasible paths, thereby generating a search tree of possible proofs. ASTtic, a deep learning-based model, generates strategies as programs in the form of abstract syntax trees. Thor combines traditional automatic theorem provers with neural strategy models to prove theorems in a neural symbolic way. TacTok uses a meta-heuristic search based on the frequency of proof strategies in existing successful proof scripts to fully automate proof script synthesis by modeling proof scripts using the semantics of written partial proof scripts and proof status. The "sledgehammer" method and search-based methods are complementary, and usually one often proves theorems that the other cannot prove. But heuristic search methods lack the ability to apply certain strategies, such as induction, which makes them unable to prove certain large classes of theorems.

[0010] In formal theorem proving, it is crucial to select useful premises from a large theorem library to solve the proof task of a given target lemma. This is a challenge for all theorem provers, especially those based on formal language models, because it is difficult for them to rigorously reason about a large number of premises as long chains of textual forms.

[0011] Existing formal theorem proof synthesis methods employ neural network models to predict the next proof step given the current theorem proof state. The proof step prediction then guides the search strategy, such as best-first search or depth-first search. Throughout the search process, the interactive theorem prover needs to verify each predicted proof step to check whether it is valid. This means that existing formal theorem proof synthesis tools require close interaction between the neural network and the interactive theorem prover. Furthermore, these calls require re-encoding of additional contextual information that the model may need at each step. Summary of the invention

[0012] The present invention provides a method and system for generating a formalized theorem proof based on a large model, which are used to solve the technical problem of high search cost in the exploration space of formalized theorem proof in the prior art.

[0013] In a first aspect, a method for generating a formalized theorem proof based on a large model is disclosed, the method comprising the following steps:

[0014] Step S1: Acquire first training data and second training data; wherein the first training data is text data including a formalized theorem proposition and all proof steps of proving the formalized theorem proposition; and the second training data is data including mathematical domain knowledge;

[0015] Step S2: inputting the second training data as data to be processed into the large model, and pre-training the large model to obtain a pre-trained large model; adjusting parameters of the pre-trained large model based on the first training data to obtain an adjusted large model;

[0016] Step S3: inputting the formalized theorem proposition of the theorem proof step to be generated as input data into the adjusted large model to generate the proof step of the formalized theorem of the theorem proof step to be generated.

[0017] Preferably, the second training data is input into the large model as data to be processed, and the large model processes the data to be processed as follows:

[0018] Step S21: pre-constructing a dictionary, the dictionary including the following information: each word segment of the formalized theorem proposition, the digital encoding of each word segment in the proof steps of proving the formalized theorem proposition, and the digital encoding of characters in UTF-8 format;

[0019] Step S22: If the data to be processed includes special characters, the special characters are converted into characters in the UTF-8 format corresponding to the special characters, and then the characters in the UTF-8 format are converted into digital codes, and the process proceeds to step S23; if the data to be processed does not include special characters, the process proceeds to step S23; wherein the special characters are logical symbols required for formal theorem proof;

[0020] Step S23: performing word segmentation processing on other characters in the data to be processed that are not digitally encoded; converting each word segmentation into a digital code corresponding to the word segmentation based on the dictionary;

[0021] Step S24: Obtain each digital code corresponding to the data to be processed, and for each digital code, generate an embedded code and a position code corresponding to the digital code in the following manner:

[0022] The digital code is converted into an embedded code by the embedding layer of the large model;

[0023] The embedded code is converted into a position code by a rotation position coding formula, and the rotation position coding formula is:

[0024]

[0025] in, The matrix vector q representing the embedding code of the formalized theorem proposition with position information m is dot-producted with the matrix k representing the embedding code of the proof step with position information n. is the rotation position encoding matrix corresponding to the formalized theorem proposition at m, W q and W k are all linearly changing parameter matrices, x m is the embedding coding matrix of the lemma in the formal theorem proof, T is the transpose, d is the dimension of the embedding coding, is the rotation position encoding matrix corresponding to the formalized theorem proposition at n, is the rotation position encoding matrix corresponding to the relative position nm, x n is the coding matrix of the proof steps;

[0026] Fusion of the embedded code and the position code corresponding to the digital code to obtain a fused code corresponding to the digital code;

[0027] Step S25: Generate an overall fusion code corresponding to the data to be processed, wherein the overall fusion code includes a fusion code of each digital code corresponding to the data to be processed.

[0028] Preferably, the large model comprises an embedded coding layer, a position coding layer, a first mean square layer, an attention calculation layer, a second mean square layer, a feedforward neural network layer and an output layer connected in sequence, the embedded coding layer converts the digital code into an embedded code, the position coding layer is used to convert the embedded code into a position code, the first mean square layer fuses the embedded code and the position code, performs layer normalization on the generated fused code, generates a normalized fused code vector, inputs the fused code vector into the attention calculation layer, and the attention calculation layer obtains the attention of the fused code vector on the formalized theorem proposition and the proof step. score, fuse the attention score with the fused coding vector to obtain a fused coding vector fused with attention information; based on each fused coding vector fused with attention information, generate an overall fused code corresponding to the data to be processed; input the overall fused code into the second mean square layer, the second mean square layer normalizes the overall fused code, and input the normalized overall fused code into the feedforward neural network layer for nonlinear transformation to obtain a feature vector representing the formal theorem proof step, and then the output layer outputs the feature vector representing the formal theorem proof step as the formal theorem proof step.

[0029] Preferably, the calculation formula of the attention score Attention(Q, K, V) is:

[0030]

[0031] Q is the query matrix, which is the embedding matrix X of the formalized theorem proposition. m Multiply by the first parameter matrix W Q The linear transformation is obtained; K is the key matrix, V is the value matrix, K is the matrix of the embedding code of the proof step multiplied by the parameter matrix W K The linear transformation is obtained, V is the embedding matrix of the proof step multiplied by the second parameter matrix W V The linear transformation is obtained, d k The dimension of the embedding encoding of V.

[0032] Preferably, the step S2, adjusting parameters of the pre-trained large model based on the first training data to obtain the adjusted large model, includes:

[0033] Step S21: adding a bypass to the pre-trained large model, the bypass and the pre-trained large model interact in input and output by superimposing a parameter matrix; the bypass includes a first matrix module and a second matrix module connected in sequence, and the input of the bypass is the overall fusion code corresponding to the data to be processed; the first matrix module performs a dimensionality reduction operation on the input of the bypass through a first low-rank matrix, and then the second matrix module performs a dimensionality increase operation on the result of the dimensionality reduction operation through a second low-rank matrix, and the result obtained is used as the output of the bypass, and the output is used as the parameter matrix that needs to be updated for the pre-trained large model;

[0034] Step S22: adjusting the parameters of the pre-trained large model according to the parameter matrix that needs to be updated for the pre-trained large model to obtain an adjusted large model.

[0035] In a second aspect, a formalized theorem proof generation system based on a large model is disclosed, the system comprising:

[0036] A data acquisition module: configured to acquire first training data and second training data; wherein the first training data is text data including a formalized theorem proposition and all proof steps of proving the formalized theorem proposition; and the second training data is data including mathematical domain knowledge;

[0037] The training module is configured to input the second training data as the data to be processed into the large model, and pre-train the large model to obtain a pre-trained large model; and adjust the parameters of the pre-trained large model based on the first training data to obtain an adjusted large model;

[0038] The result generation module is configured to input the formalized theorem proposition of the theorem proof step to be generated as input data into the adjusted large model, and generate the proof steps of the formalized theorem of the theorem proof step to be generated.

[0039] In a third aspect, an electronic device is disclosed, the electronic device comprising:

[0040] at least one processor; and

[0041] a memory communicatively connected to the at least one processor; wherein,

[0042] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described above.

[0043] In a fourth aspect, a non-transitory computer-readable storage medium storing computer instructions is disclosed, wherein the computer instructions are used to cause the computer to execute the method as described above.

[0044] The large model has the ability to process and generate human-like text. By fine-tuning the large language model to generate proofs, the present invention can simplify the theorem proving steps and greatly reduce the complexity and cost of the fine-grained interaction between the prediction model and the proof assistant required by the search-based method. The proof goal is input into the large model as a prompt, so that it directly generates a complete formalized theorem proof steps, and then the corresponding interactive theorem proving assistant is used to verify the correctness of the proof, thereby helping the automatic theorem prover to narrow the search space.

[0045] The method of the present invention is a simpler method for synthesizing formal theorem proofs. It fine-tunes the large model to generate a complete proof of the target lemma without the need for search proofs or "sledgehammers". Compared with the heuristic search method driven by a small model, this method generates very little additional computation while making full use of the excellent reasoning capabilities of the large model. It also simplifies the steps of theorem proof generation, greatly reducing the complexity and cost of the fine-grained interaction between the prediction model and the proof assistant required by the search-based method.

[0046] The method of the present invention only needs to make one call and process the context information once, and simultaneously sample multiple proof steps to generate a complete proof by fine-tuning a large model. The method of the present invention simplifies the fine-grained interaction between the neural network model and the interactive theorem prover, allowing the user to run the work of generating proofs and checking completely independently. Not only can the complexity of automatically generating theorem proofs be greatly reduced, but also the hardware utilization during model reasoning can be significantly improved. And when additional context information is provided to the large model, it is not necessary to reprocess the context for each proof step, but only needs to be processed once for each proof. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A flowchart diagram of the method for generating formal theorem proving steps based on large models;

[0048] Figure 2 A flowchart of the interaction between the large model-based formal theorem proof step generation method and the interactive theorem prover after generating proof steps;

[0049] Figure 3 A schematic diagram of a process for generating digital codes corresponding to training data generated by preprocessing training data;

[0050] Figure 4 A schematic diagram of the process of embedding and position encoding digital codes;

[0051] Figure 5 This is a schematic diagram of the large model training process;

[0052] Figure 6 It is a structural schematic diagram of a large model of the present invention;

[0053] Figure 7 Schematic diagram of the input training data format for the supervised fine-tuning process;

[0054] Figure 8 Detailed LoRA fine-tuning diagram to supervise the fine-tuning process;

[0055] Fig. 9 Schematic diagram of the greedy algorithm decoding of the model prediction process;

[0056] Fig.10 Generate a systematic architectural diagram for formal theorem proving steps based on large models. DETAILED DESCRIPTION

[0057] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0058] The present invention provides a formalized theorem proof generation method based on a large model, the method comprising the following steps:

[0059] Step S1: obtaining first training data, wherein the first training data is text data including a formalized theorem proposition and all proof steps of proving the formalized theorem proposition; obtaining second training data, wherein the second training data is data including mathematical domain knowledge;

[0060] Step S2: using the second training data as data to be processed, inputting the data to be processed into the large model, and pre-training the large model to obtain a pre-trained large model; adjusting parameters of the pre-trained large model based on the first training data to obtain an adjusted large model;

[0061] Step S3: inputting the formalized theorem proposition of the theorem proof step to be generated as input data into the adjusted large model to generate the proof step of the formalized theorem of the theorem proof step to be generated.

[0062] like Figure 2 As shown, after generating the proof steps of the formalized theorem of the theorem proof steps to be generated, the proof steps are input into the interactive theorem prover to verify the generated proof steps.

[0063] Furthermore, the present invention can be applied to the inspection of the security of computer systems, taking certain current characteristics (such as security attributes) or behaviors of the computer system as formalized theorem propositions to be generated for theorem proof steps, and then using the theorem proof steps generated by the method of the present invention as the basis for system verification, thereby providing a rigorous and logically complete method to ensure that important attributes of the computer system are met.

[0064] In computer science, formal theorem proving is a method that uses mathematical logic to verify system properties. In order to apply this method to real systems, it is necessary to convert certain characteristics (such as security properties) or behaviors of the computer system into formal theorem propositions. The following are the required conversion steps: (1) Select a characteristic of the computer system (such as a security property), such as "the system does not allow unauthorized access", or a functional property, such as "the system always responds to every input". (2) Define a formal language: Next, you need to select or define a formal language that can describe the state and behavior of the computer system. This language usually contains logical symbols and axioms to facilitate expression and reasoning. (3) Convert to formal theorem proposition: Convert the selected computer system characteristics into formal propositions. For example, "the system does not allow unauthorized access" is formalized as "for all users u and actions a, if u is not authorized to perform a, then the system will not perform a".

[0065] The generated theorem proof steps have the following uses: (1) As a basis for computer system verification: If the theorem proof is successful, these steps provide mathematical evidence that the computer system meets the set properties. (2) Documentation and evidence: The proof steps can be used as documentation to show evidence of the security of the computer system, especially in situations where compliance certification is required. (3) A tool for debugging and improvement: If the theorem proof fails, the proof steps can help developers understand why the computer system does not meet specific properties and guide them to make necessary modifications. In general, formal theorem proving provides a rigorous and logically complete method to ensure that important properties of a computer system are met. This method is particularly important in safety-critical computer systems because it can provide a higher level of assurance than traditional testing methods. The present invention can apply the method of checking the security of computer systems to aerospace control software, operating system kernels, compilers, hardware design, network protocols and other fields.

[0066] The big model is a scaled-up Transformer model trained on a large amount of text data (including natural language and code), which has been proven to be very effective in various applications, including question answering, text and code generation. The present invention is based on the formal theorem proving step generation method of the big model, the core content of which is to construct a formal theorem proving fine-tuning dataset, use the big model to vectorize the current proof target, and enable the big model to directly generate a complete formal theorem proving code.

[0067] The present invention constructs a formalized theorem proof fine-tuning dataset including proof premise, proof target, proof status and proof steps, which is used to give the learned model additional context when the big model generates a complete theorem proof, and further improve the automatic proof generation. The big model is used to vectorize and match the theorems in the mathematical library and the current proof target respectively, and the most likely theorems to be used are screened out, helping the automatic theorem prover of pure symbolic calculation to narrow the proof search space. The present invention trains and fine-tunes the big model of formalized theorem proof based on the pre-trained big model Llemma, without the need to use a "sledgehammer" or computationally expensive search. And the proof target is input into the big model as a prompt, so that it directly generates the corresponding formalized theorem proof code, and then the corresponding formal verifier is used to judge the correctness of the proof.

[0068] In the present invention, Figure 3-Figure 4 As shown, the second training data is used as the data to be processed, and the data to be processed is input into the large model, and the large model processes the data to be processed as follows:

[0069] Step S21: pre-constructing a dictionary, the dictionary including the following information: digital codes of each word of the formalized theorem proposition and each word in the proof steps of proving the formalized theorem proposition, and digital codes of characters in UTF-8 format;

[0070] Step S22: If the data to be processed includes special characters, the special characters are converted into characters in the UTF-8 format corresponding to the special characters, and the characters in the UTF-8 format are converted into digital codes, and the process proceeds to step S23; otherwise, the process proceeds to step S23; wherein the special characters are logical symbols required in formalizing theorem proofs;

[0071] Step S23: performing word segmentation processing on other characters in the data to be processed that are not digitally encoded; converting each word segmentation into a digital code corresponding to the word segmentation based on the dictionary;

[0072] Step S24: Obtain each digital code corresponding to the data to be processed, and for each digital code, generate an embedded code and a position code corresponding to the digital code in the following manner:

[0073] The digital code is converted into an embedded code by the embedding layer of the large model;

[0074] The embedded code is converted into a position code by a rotation position coding formula, and the rotation position coding formula is:

[0075]

[0076] in, The matrix vector q representing the embedding code of the formalized theorem proposition with position information m is dot-producted with the matrix k representing the embedding code of the proof step with position information n. is the rotation position encoding matrix corresponding to the formalized theorem proposition at m, W q and W k are all linearly changing parameter matrices, x m is the embedding coding matrix of the lemma in the formal theorem proof, T is the transpose, d is the dimension of the embedding coding, is the rotation position encoding matrix corresponding to the formalized theorem proposition at n, is the rotation position encoding matrix corresponding to the relative position nm, x n is the coding matrix of the proof steps;

[0077] Fusion of the embedded code and the position code corresponding to the digital code to obtain a fused code corresponding to the digital code;

[0078] Step S25: Generate an overall fusion code corresponding to the data to be processed, wherein the overall fusion code includes a fusion code of each digital code corresponding to the data to be processed.

[0079] In the present invention, the embedding layer of the large model converts the digital code into a high-dimensional embedded code vector. The correspondence between the digital code in the embedding layer and the high-dimensional embedded code vector is learned by the large model in the pre-training stage by calculating the loss function through gradient descent. For example, the digital code "10383" corresponding to "lemma" is encoded into a 512-dimensional embedded code vector [2.0808, -2.8327, ..., 1.0319, 2.6812] through the embedding layer. In order to maintain the order of the sequence, the rotation position encoding is used to inject it into the code vector. The rotation position encoding RoPE assigns position information to a vector by rotating it by a certain angle, that is, the rotation position encoding formula converts the embedded code into a position code.

[0080] like Figure 3As shown in the figure, the language model is used to reason about text. Since the large model cannot process text data directly, the formal theorem proving language is encoded into numbers. The approach is similar to looking up a dictionary. A dictionary is constructed, which contains all the words that appear in the formal theorem proving language, such as "lemma", "proof", "by", etc. Each word segment is an element in the dictionary, forming a list. The formal theorem proving statement composed of word segments can be converted into a digital expression composed of the digital ID of each word segment. Data preprocessing specifically includes three steps:

[0081] (1) Escape special characters in the formal theorem proof text into UTF-8 format characters;

[0082] (2) Use a word segmenter to segment text data into words according to the subword segmentation strategy;

[0083] (3) Map all segmented words to corresponding numbers according to the vocabulary.

[0084] Formal theorem proving code uses a lot of non-ASCII symbols to enhance the readability of the code, but the big model cannot recognize non-ASCII symbols, so they need to be translated into UTF-8 format characters that the big model can recognize. For example Escaped to "\\Rightarrow", Escapes to "\\exists", Escaped to "\\notin" etc.

[0085] The subword segmentation strategy refers to directly retaining high-frequency words, and low-frequency words are segmented into more meaningful subwords. For example, "tokenization" is a low-frequency word, which can be segmented into "token" and "ization". These two subwords not only appear more frequently, but also retain their meaning. This strategy can cover most of the text with a smaller vocabulary, and basically no unknown segmented words will be generated.

[0086] The vocabulary is the mapping between word segmentation and digital ID learned by the large model on a large amount of text corpus. The corresponding digital IDs of semantically close word segmentation are also closer. For example, "lemma" is mapped to the number "10383", "not" is mapped to the number "1333", and "proof" is mapped to the number "5296".

[0088] like Figure 4As shown in the figure, the embedding layer can map word segments to a high-dimensional vector space, so that the vector contains the semantic information of the word segment or sentence, allowing the large model to better understand the meaning of the formal theorem proof statement. The embedding layer converts the input formal theorem proof statement into a vector of a fixed dimension, such as 512 dimensions. In this way, the large model can process input sequences of different lengths and map them to a vector space of the same dimension. The specific meaning of each dimension of each word embedding code does not need to be manually defined, and the model can be automatically learned through training.

[0089] Large models have the ability to process data in high parallelism, but the disadvantage of parallelism is that large models do not have the ability to process the position information of sequence data, so an additional positional encoding (Positional Embedding) layer is required to provide position information. The positional encoding layer generates a unique vector of the same dimension, such as 512 dimensions, for each word position in the sentence, so that the model can better distinguish between words at different positions.

[0090] The dimensions of the generated embedding coding matrix and the position coding matrix are consistent, so the original sequence is added with position information by directly adding the embedded coded sequence to the corresponding position of the position coding matrix. The rows of the embedded coding matrix in the figure represent the high-dimensional coding vectors corresponding to the numbers mapped by the word segmentation. For example, the digital id corresponding to the word segmentation "lemma" is "10383", and its embedded coded high-dimensional vector is [2.0808, -2.8327, 1.0516, ..., 2.6114, 1.0319, 2.6812], where the dimension of the coding vector is a hyperparameter, assuming it is 512 dimensions. "lemma" is located at the first position in the formal theorem proving language sequence, that is, position index 0, where the position coding vector of position 0 is [0.0000, 1.0000, 0.0000., ..., 0.000, 1.0000, 0.0000]. Adding the embedded coding vector corresponding to the first word “lemma” in the formal theorem proving language to the positional coding vector corresponding to position index 0 gives the coding vector with position information, which is [2.0808, -1.8327, 1.0516, …, 2.6114, 2.0319, 2.6812].

[0091] In the present invention, the step S2: taking the second training data as the data to be processed, inputting the data to be processed into the large model, and pre-training the large model to obtain a pre-trained large model, for example, using a Code Llama large model based on a base model, after training with a large amount of corpus in mathematics-related fields, to obtain a Llemma-7B large model adapted to the mathematics field.

[0092] In the present invention, the large model is pre-trained by the second training data to obtain a pre-trained large model, the purpose of which is to enable the large model to have mathematical knowledge and be able to handle problems in the mathematical field.

[0093] like Figure 6 As shown, the large model includes an embedded coding layer, a position coding layer, a first mean square layer, an attention calculation layer, a second mean square layer, a feedforward neural network layer and an output layer connected in sequence. The embedded coding layer converts the digital code into an embedded code, the position coding layer is used to convert the embedded code into a position code, the first mean square layer fuses the embedded code and the position code, performs layer normalization on the generated fused code, generates a normalized fused code vector, and inputs the fused code vector into the attention calculation layer, and the attention calculation layer obtains the attention of the fused code vector on the formalized theorem proposition and the proof steps. score, fuse the attention score with the fused coding vector to obtain a fused coding vector fused with attention information; based on each fused coding vector fused with attention information, generate an overall fused code corresponding to the data to be processed; input the overall fused code into the second mean square layer, the second mean square layer normalizes the overall fused code, input the normalized overall fused code into the feedforward neural network layer for nonlinear transformation to obtain a feature vector representing the formal theorem proof step, and then the output layer outputs the feature vector representing the formal theorem proof step as the proof step of the formal theorem;

[0094] Among them, the calculation formula of attention score Attention(Q,K,V) is:

[0095]

[0096] Q is the query matrix, which is the embedding matrix X of the formalized theorem proposition. m Multiply by the first parameter matrix W Q The linear transformation is obtained; K is the key matrix, V is the value matrix, K is the matrix of the embedding code of the proof step multiplied by the parameter matrix W K The linear transformation is obtained, V is the matrix of the embedded code in the proof step multiplied by the second parameter matrix W V The linear transformation is obtained, d k The dimension of the embedding encoding of V.

[0097] In the present invention, the parameters of the pre-trained large model are adjusted based on the first training data to obtain the adjusted large model, the purpose of which is to further fine-tune the parameters of the pre-trained large model, make slight adjustments to the additional parameters of the pre-trained model, and enable the fine-tuned large model to generate the proof steps required for the proof.

[0098] In step S2, the pre-trained large model is adjusted based on the first training data to obtain an adjusted large model, including:

[0099] Step S21: Add a bypass to the pre-trained large model. The bypass interacts with the pre-trained large model in terms of input and output through the superposition of parameter matrices. The bypass includes a first matrix module and a second matrix module connected in sequence. The input of the bypass is the overall fusion encoding corresponding to the data to be processed. The first matrix module performs a dimensionality reduction operation on the input of the bypass through a first low-rank matrix, and then the second matrix module performs a dimensionality increase operation on the result of the dimensionality reduction operation through a second low-rank matrix. The obtained result is used as the output of the bypass, and this output is used as the parameter matrix that needs to be updated for the pre-trained large model.

[0100] Step S22: Adjust the parameters of the pre-trained large model according to the parameter matrix that needs to be updated for the pre-trained large model to obtain an adjusted large model.

[0101] In the present invention, the pre-trained large model is adjusted by using the LoRA fine-tuning method to obtain an adjusted large model. LoRA fine-tuning does not change the original pre-trained parameters of the large model. Instead, a small number of new parameters are fine-tuned for specific tasks. These new parameters need to be used in combination with the original pre-trained parameters. The parameters of the bypass and the original parameters are directly combined, that is, the parameters are added, so that the inference time will not be increased at all. Large models are over-parameterized. When used for specific tasks, in fact, only a small part of the parameters play a major role. That is, the dimension of the parameter matrix is very high, but it can be approximated by low-dimensional matrix decomposition.

[0102] First, add a bypass next to the original pre-trained language model and perform dimensionality reduction and then dimensionality increase operations to simulate the intrinsic rank. Second, initialize A with a random Gaussian distribution and initialize B with a zero matrix. The dimension of matrix A is d*r, and the dimension of matrix B is r*d, where r << d. Generally, r takes 1, 2, 4, 8. During training, the parameters of the pre-trained model are fixed, and only matrices A and B are trained. Finally, after training is completed, the product of matrix B and matrix A is combined with the pre-trained model parameters as the fine-tuned model parameters. During fine-tuning, the number of parameters of this bypass will be much smaller than the parameters W of the original network, as Figure 8 shown.

[0103] As Figure 7 shown, the pre-trained large model can also be adjusted based on the first training data in the following manner.

[0104] First, deploy the model to a server with 4 RTX-3090 graphics cards, and the video memory of each graphics card is 24G.

[0105] The Llemma-7B large model is fine-tuned according to the instructions. In order to obtain the expected characteristics and performance, it is necessary to follow the specific format defined by it, including query and response tags. The training data format of the instruction fine-tuning stage is shown in the figure, and the corresponding structure adopts " <query response>The request part is the input data of the model, and its content is the theorem statement part of the formalized theorem proving language. The response part is the output label data of the model, and its content is the complete theorem proof steps corresponding to the theorem statement part. For example, {query:"lemma\"\\not surj(f::'a\\Rightarrow'a set)\"\n",response:"proof\n assume\"surj f\"\n hence\"\\existsa.{xx\\notin fx}=fa\"by(auto simp:surj_def)\n thus\"False\"by blast\nqed"}.

[0106] Furthermore, the parameter adjustment of the pre-trained large model based on the first training data to obtain the adjusted large model includes: setting the number of iterations and hyperparameters of iterations, training the pre-trained large model with the first training data to obtain the adjusted large model.

[0107] Furthermore, the preset file save address is used to store the adjusted large model.

[0108] The prediction results of this method are as follows Fig. 9 As shown in the figure, during the model decoding process, the model continues to predict the next result based on the previous one, and infers in sequence. At this time, in order to generate a complete sentence, it is necessary to fuse the outputs of multiple steps. The goal is to maximize the product of the conditional probabilities of each step in the output sequence.

[0109] The most direct method is the greedy search algorithm, which takes the output with the highest probability at each step, and then takes the output from the beginning to the current step as input to predict the next step until the end of the sentence. As shown in the figure below, the first step is to go to the "proof" with the highest probability, followed by "assume", "surj", and so on.

[0110] The present invention constructs a formalized theorem proof fine-tuning dataset including proof premise, proof target, proof status and proof steps. A method for using a large model to vectorize and match the theorems in a mathematical library and the current proof target respectively. A fine-tuning method for inputting the proof target as a prompt into the large model to directly generate the corresponding complete formalized theorem proof code at one time.

[0111] like Fig.10 As shown, the present invention provides a formalized theorem proof generation system based on a large model, the system comprising:

[0112] A data acquisition module: configured to acquire first training data and second training data; wherein the first training data is text data including a formalized theorem proposition and all proof steps of proving the formalized theorem proposition; and the second training data is data including mathematical domain knowledge;

[0113] The training module is configured to input the second training data as the data to be processed into the large model, and pre-train the large model to obtain a pre-trained large model; and adjust the parameters of the pre-trained large model based on the first training data to obtain an adjusted large model;

[0114] The result generation module is configured to input the formalized theorem proposition of the theorem proof step to be generated as input data into the adjusted large model, and generate the proof steps of the formalized theorem of the theorem proof step to be generated.

[0115] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, it should be understood by those skilled in the art that the technical solutions described in the above embodiments can still be modified, or some or all of the technical features therein can be replaced by equivalents, and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.< / query>

Claims

1. A formalized theorem proof generation method based on a large model, characterized in that: The method comprises the following steps: Step S1: Acquire first training data and second training data; wherein the first training data is text data including a formalized theorem proposition and all proof steps of proving the formalized theorem proposition; and the second training data is data including mathematical domain knowledge; Step S2: inputting the second training data as data to be processed into the large model, and pre-training the large model to obtain a pre-trained large model; adjusting parameters of the pre-trained large model based on the first training data to obtain an adjusted large model; Step S3: inputting the formalized theorem proposition of the theorem proof step to be generated as input data into the adjusted large model to generate the proof step of the formalized theorem of the theorem proof step to be generated.

2. The method according to claim 1, characterized in that The second training data is input into the large model as the data to be processed, and the large model processes the data to be processed as follows: Step S21: pre-constructing a dictionary, the dictionary including the following information: each word segment of the formalized theorem proposition, the digital encoding of each word segment in the proof steps of proving the formalized theorem proposition, and the digital encoding of characters in UTF-8 format; Step S22: If the data to be processed includes special characters, the special characters are converted into characters in the UTF-8 format corresponding to the special characters, and then the characters in the UTF-8 format are converted into digital codes, and the process proceeds to step S23; if the data to be processed does not include special characters, the process proceeds to step S23; wherein the special characters are logical symbols required for formal theorem proof; Step S23: performing word segmentation processing on other characters in the data to be processed that are not digitally encoded; converting each word segmentation into a digital code corresponding to the word segmentation based on the dictionary; Step S24: Obtain each digital code corresponding to the data to be processed, and for each digital code, generate an embedded code and a position code corresponding to the digital code in the following manner: The digital code is converted into an embedded code by the embedding layer of the large model; The embedded code is converted into a position code by a rotation position coding formula, and the rotation position coding formula is: in, The matrix vector q representing the embedding code of the formalized theorem proposition with position information m is dot-producted with the matrix k representing the embedding code of the proof step with position information n. is the rotation position encoding matrix corresponding to the formalized theorem proposition at m, W q and W k are all linearly changing parameter matrices, x m is the embedding coding matrix of the lemma in the formal theorem proof, T is the transpose, d is the dimension of the embedding coding, is the rotation position encoding matrix corresponding to the formalized theorem proposition at n, is the rotation position encoding matrix corresponding to the relative position nm, x n is the coding matrix of the proof steps; Fusion of the embedded code and the position code corresponding to the digital code to obtain a fused code corresponding to the digital code; Step S25: Generate an overall fusion code corresponding to the data to be processed, wherein the overall fusion code includes a fusion code of each digital code corresponding to the data to be processed.

3. The method according to claim 2, characterized in that The large model includes an embedded coding layer, a position coding layer, a first mean square layer, an attention calculation layer, a second mean square layer, a feedforward neural network layer and an output layer connected in sequence, the embedded coding layer converts the digital code into an embedded code, the position coding layer is used to convert the embedded code into a position code, the first mean square layer fuses the embedded code and the position code, performs layer normalization processing on the generated fused code, generates a normalized fused code vector, and inputs the fused code vector into the attention calculation layer, the attention calculation layer obtains the attention score of the fused code vector between the formalized theorem proposition and the proof step, fuses the attention score with the fused code vector, and obtains a fused code vector fused with attention information; based on each fused code vector fused with attention information, generates an overall fused code corresponding to the data to be processed; The overall fusion code is input into the second mean square layer, the second mean square layer normalizes the overall fusion code, the normalized overall fusion code is input into the feedforward neural network layer for nonlinear transformation to obtain a feature vector representing the formal theorem proof step, and then the output layer outputs the feature vector representing the formal theorem proof step as the proof step of the formal theorem.

4. The method according to claim 3, characterized in that The calculation formula of attention score Attention(Q,K,V) is: Q is the query matrix, which is the embedding matrix X of the formalized theorem proposition. m Multiply by the first parameter matrix W Q The linear transformation is obtained; K is the key matrix, V is the value matrix, K is the matrix of the embedding code of the proof step multiplied by the parameter matrix W K The linear transformation is obtained, V is the matrix of the embedded code in the proof step multiplied by the second parameter matrix W V The linear transformation is obtained, d k The dimension of the embedding encoding of V.

5. The method according to claim 1, characterized in that The step S2, adjusting parameters of the pre-trained large model based on the first training data to obtain an adjusted large model, includes: Step S21: adding a bypass to the pre-trained large model, the bypass and the pre-trained large model interact in input and output by superimposing a parameter matrix; the bypass includes a first matrix module and a second matrix module connected in sequence, and the input of the bypass is the overall fusion code corresponding to the data to be processed; the first matrix module performs a dimensionality reduction operation on the input of the bypass through a first low-rank matrix, and then the second matrix module performs a dimensionality increase operation on the result of the dimensionality reduction operation through a second low-rank matrix, and the result obtained is used as the output of the bypass, and the output is used as the parameter matrix that needs to be updated for the pre-trained large model; Step S22: adjusting the parameters of the pre-trained large model according to the parameter matrix that needs to be updated for the pre-trained large model to obtain an adjusted large model.

6. A formalized theorem proof generation system based on a large model, characterized in that: The system comprises: A data acquisition module: configured to acquire first training data and second training data; wherein the first training data is text data including a formalized theorem proposition and all proof steps of proving the formalized theorem proposition; and the second training data is data including mathematical domain knowledge; The training module is configured to input the second training data as the data to be processed into the large model, and pre-train the large model to obtain a pre-trained large model; and adjust the parameters of the pre-trained large model based on the first training data to obtain an adjusted large model; The result generation module is configured to input the formalized theorem proposition of the theorem proof step to be generated as input data into the adjusted large model, and generate the proof steps of the formalized theorem of the theorem proof step to be generated.

7. An electronic device, characterized in that: The device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 5.

8. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Theorem proving method and device based on machine learning, electronic equipment and storage medium

    CN110443369A

  • Automatic theorem proving method and device based on conflict deduction and storage medium

    CN113379052A

  • Text information extraction method based on large language model and efficient parameter fine tuning

    CN118132674A

Cited By

  • Proposition method and system combining large model and inference engine, medium and product

    CN119476246A

  • Interactive theorem proving system and method based on large language model

    CN120163213A

  • Formalized automatic theorem proving method based on large language model

    CN121436106A

  • Form verification method and system for RISC-V multi-core SBI firmware

    CN121742924A