Extracting Operator Trees from Model Embeddings

Anja Reusch, Wolfgang Lehner2022

Abstract

Transformer-based language models are able to capture several linguistic properties such as hierarchical structures like dependency or constituency trees. Whether similar structures for mathematics are extractable from language models has not yet been explored. This work aims to probe current state-of-the-art models for the extractability of Operator Trees from their contextualized embeddings using the structure probe designed by Hewitt and Manning. We release the code and our data set for future analysis.

Introduction

While Transformer models like BERT and RoBERTa have revolutionized Natural Language Processing, their internal "understanding" of mathematics remains largely opaque. While these models excel at tasks like mathematical question answering or formula retrieval, a fundamental question remains: do they internalize the underlying hierarchical structure of equations?

In linguistics, BERT is known to encode syntax through dependency trees. In the mathematical domain, the equivalent structure is the Operator Tree (OPT)—a hierarchical representation where operators (e.g., $+$, $\int$, $\frac{}{}$) serve as nodes and their arguments as children. This research investigates whether this structural information is embedded within the high-dimensional vector space of models trained on mathematical and scientific data.

An example of an Operator Tree (OPT) representing a mathematical formula.

Methodology: The Structural Probe

To identify these structures, the authors utilize a Structural Probe, a technique pioneered by Hewitt and Manning (2019). The probe attempts to find a linear transformation (matrix $B$) that maps contextualized embeddings into a space where the L2 distance between token vectors approximates their distance within the actual Operator Tree. Successful extraction of these trees with high accuracy implies that the model has implicitly learned the mathematical hierarchy during pre-training.

The study evaluated 13 models, ranging from general-purpose baselines (BERT, RoBERTa, ALBERT) to domain-specific models (SciBERT) and math-pretrained variants (MathBERT, and models further trained on the ARQMath dataset).

Data and Parsing

The researchers utilized formulas from the ARQMath 2020 corpus, sourced from Mathematics StackExchange posts. The dataset comprised 50,000 formulas for training the probe, with 10,000 each for development and testing. Because standard LaTeX parsers do not map tokens directly to tree nodes, a custom Python-based LaTeX parser was developed to generate the "gold standard" Operator Trees used for evaluation.

Key Findings

The Impact of Math Pre-training

A primary insight is that specialized pre-training is essential. Models specifically exposed to mathematical corpora showed significant improvements in structural extractability. For instance, AnReu/math_pretrained_bert achieved a Distance Spearman (DSpr) of 0.815 and an Undirected Unlabeled Attachment Score (UUAS) of 0.700, markedly outperforming the base bert-base-cased (DSpr 0.713, UUAS 0.532).

The "Middle Layer" Phenomenon

The probe revealed that structural information is not uniformly distributed across model layers. In BERT and RoBERTa-based models, extractability typically peaks in the middle layers (Layer 6 or 7 for base models; Layers 9–13 for large models). This suggests a functional hierarchy: lower layers process local features, middle layers organize global structure, and top layers specialize in the final pre-training objective (e.g., masked token prediction).

Performance (DSpr) across layers for various models, highlighting the peak in middle layers for BERT-based models and early layers for ALBERT.

Model-Specific Variations

  • ALBERT: Unlike BERT, ALBERT (which shares weights across layers) exhibited its best structural encoding in early layers (Layers 2–3).
  • SciBERT: While SciBERT outperformed base BERT, it lagged behind math-specific models, indicating that general scientific context is insufficient for capturing deep mathematical logic.
  • The "=" Root: Qualitative analysis indicated that models struggle with the equal sign, which often serves as the root of the tree, while performing well on local structures like fractions or exponents.

Conclusion and Limitations

While the ability to extract Operator Trees is a significant finding, the authors note that correlation does not imply causation; it remains unclear if models actively use these trees to solve problems. Furthermore, the discrepancy in models like ALBERT—which show poor structural extractability but high performance on downstream tasks—suggests that some architectures may rely on non-hierarchical strategies. Future research will expand this probing to other mathematical representations and complex symbolic reasoning tasks.

Summary updated

BibTeX
@misc{reusch2022extracting,
  author = {Anja Reusch and Wolfgang Lehner},
  title = {{Extracting Operator Trees from Model Embeddings}},
  year = {2022},
  doi = {10.18653/v1/2022.mathnlp-1.6},
}
Figure