TL;DR
FormalAlign is a novel, automated framework designed to evaluate the semantic alignment between natural language mathematical statements and their machine-verifiable formal counterparts. By employing a dual-loss training strategy that combines sequence generation with contrastive representational learning, FormalAlign significantly outperforms GPT-4 in detecting subtle translation errors. It offers a highly scalable, efficient alternative to tedious manual verification.
The Challenge of Semantic Alignment
Autoformalization is the process of translating "informal" mathematics—the natural language way humans write proofs—into "formal" languages like Lean 4 that computers can rigorously verify. While Large Language Models (LLMs) have become increasingly adept at generating formal code, a critical bottleneck remains: we lack a reliable, automated way to check if the generated code actually means what the original text intended.
Current evaluation methods typically fall into two traps:
- Logical Validity vs. Semantic Accuracy: A formal compiler (like Lean) can confirm if the code is syntactically correct and logically sound. However, it cannot tell you if the LLM accidentally changed a "7" to a "4" or swapped an equality for an inequality. The statement might be valid, but it solves the wrong problem.
- Surface-Level Matching: Traditional metrics like BLEU or BERTScore measure word or token overlap. In mathematics, a single character change (e.g., changing
=to\neq) completely alters a theorem's meaning, yet these metrics will still report a 99% similarity score.
Until now, the only "gold standard" for checking semantic alignment was manual human review. This process is slow, expensive, and impossible to scale for massive, modern datasets.
The FormalAlign Framework
To overcome these limitations, researchers introduced FormalAlign, a framework that fine-tunes an LLM (specifically Mistral-7B) using a mutually enhancing dual-loss objective:
- Autoformalization Task ($L_{CE}$): A standard cross-entropy loss that trains the model to predict the next token in a formal sequence given an informal natural language input.
- Alignment Task ($L_{CL}$): A contrastive loss that encourages the model to create similar internal "hidden state" representations for matching informal-formal pairs, while pushing non-matching (misaligned) pairs further apart in the embedding space.
During inference, the model evaluates a translation by producing an Alignment Score ($V_{align}$). This score is the average of two components:
- Certainty Score ($V_{cer}$): How confident the model is in generating the formal output.
- Similarity Score ($V_{sim}$): The cosine similarity between the embeddings of the natural language prompt and the generated formal statement.
Datasets and Misalignment Strategies
The model was trained on FormL4 and MMA (derived from Mathlib). To rigorously evaluate its ability to detect errors, the researchers created a suite of "misaligned" examples using six distinct strategies:
- Constant/Exponent Modification: Changing numbers or mathematical powers.
- Variable Changes: Introducing new variables or altering their types (e.g., changing a Real number to an Integer).
- Logical Swaps: Flipping operators, such as changing $=$ to $\neq$.
- Random Pairing: Matching a prompt with a completely unrelated formal statement.
Evaluation was performed across four benchmarks: FormL4-Basic, FormL4-Random, MiniF2F-Valid, and MiniF2F-Test.
Key Insights and Results
The dual-loss approach proved to be a significant breakthrough. The contrastive alignment task acts as a powerful form of data augmentation, helping the model understand the structure and constraints of the math, rather than just the syntax.
- Outperforming GPT-4: FormalAlign achieved an Alignment-Selection (AS) score of 99.21% on FormL4-Basic, comfortably beating GPT-4’s 88.91%. On the more challenging MiniF2F-Valid set, it outperformed GPT-4 by 3.19% (66.39% vs. 64.34%).
- Massive Precision Gains: In the FormL4-Basic detection task, FormalAlign reached 93.65% precision. This is vastly superior to GPT-4’s 42.68%, as GPT-4 struggled heavily with false positives.
- Unmatched Efficiency: While human experts took roughly 3 hours to review 80 items, FormalAlign completed the exact same task in under 2 minutes with a 65% correctness ratio (compared to the human average of ~80%).
- Strong Generalization: Despite being trained primarily on Mathlib-style data, the model generalized well to the competition-level math problems found in the MiniF2F dataset.
Limitations and Future Work
While FormalAlign represents a massive leap forward for automated metrics, it still trails human experts by about 15% in overall correctness. It occasionally struggles with very subtle contextual shifts that require deep, intuitive mathematical reasoning.
Furthermore, most of the "negative" examples used for testing were synthetically generated. While these correlate well with real-world errors, actual LLM-generated mistakes can sometimes be more nuanced or multi-layered. Future iterations of FormalAlign could bridge this gap by integrating formal reasoning systems—like the Lean solver itself—more tightly into the evaluation loop, bringing automated evaluation even closer to human-level accuracy.
Summary updated