[Paper Review] Linear algebra with transformers
This paper demonstrates that small transformers can learn to perform complex linear algebra operations—such as matrix multiplication, eigenvalue decomposition, and inversion—directly from numerical examples, achieving over 90% accuracy using four distinct encoding schemes for real numbers. The models generalize robustly to out-of-distribution matrices, particularly when trained on Laplace-distributed eigenvalues, suggesting transformers can handle non-trivial numerical computations despite prior struggles with basic arithmetic.
Transformers can learn to perform numerical computations from examples only. I study nine problems of linear algebra, from basic matrix operations to eigenvalue decomposition and inversion, and introduce and discuss four encoding schemes to represent real numbers. On all problems, transformers trained on sets of random matrices achieve high accuracies (over 90%). The models are robust to noise, and can generalize out of their training distribution. In particular, models trained to predict Laplace-distributed eigenvalues generalize to different classes of matrices: Wigner matrices or matrices with positive eigenvalues. The reverse is not true.
Motivation & Objective
- To investigate whether transformers can learn numerical linear algebra operations from pure example-based training, despite known difficulties with basic arithmetic.
- To evaluate the effectiveness of different encoding schemes for representing real numbers in sequence models.
- To assess generalization capabilities of trained models beyond their training distribution, especially for eigenvalue-related tasks.
- To explore the role of random matrix theory in enabling out-of-distribution generalization in neural networks.
- To demonstrate that transformers can serve as computational building blocks for AI for science, even if not replacing traditional numerical libraries.
Proposed method
- Transformers are trained end-to-end on sequences of tokens representing matrices encoded in scientific notation with three significant digits.
- Four encoding schemes—P10, P1000, B1999, and FP15—are proposed and evaluated for representing real numbers in the input and output sequences.
- Each linear algebra problem (e.g., matrix transposition, inversion, SVD) is framed as a sequence-to-sequence task using a standard transformer architecture.
- Models are trained on large datasets of randomly generated matrices, with ground-truth outputs computed via NumPy’s linalg module.
- The architecture includes asymmetric configurations, such as single-layer encoders or decoders, to study efficiency and performance trade-offs.
- Generalization is evaluated by testing on matrices with different statistical properties (e.g., Wigner matrices, positive-definite matrices), particularly focusing on eigenvalue distributions.
Experimental results
Research questions
- RQ1Can transformers learn complex linear algebra operations like eigenvalue decomposition and matrix inversion from purely numerical examples?
- RQ2How do different real-number encoding schemes affect model performance and generalization in numerical computation tasks?
- RQ3To what extent can models trained on one class of matrices (e.g., Laplace-distributed eigenvalues) generalize to other matrix types (e.g., Wigner matrices)?
- RQ4Does the use of random matrix theory principles improve generalization in transformer-based numerical computation?
- RQ5Can small, efficient transformers achieve high accuracy on numerical linear algebra tasks without relying on symbolic manipulation?
Key findings
- Transformers trained on random matrices achieve over 90% accuracy on all nine linear algebra tasks, with most exceeding 99% accuracy.
- Models trained to predict Laplace-distributed eigenvalues generalize effectively to Wigner matrices and positive-definite matrices, but the reverse is not true.
- The models are robust to input noise, maintaining high accuracy even under significant perturbations in matrix coefficients.
- The choice of encoding scheme significantly impacts performance, with FP15 and B1999 showing better results than P10 and P1000 for complex tasks.
- Asymmetric architectures—such as 6-layer encoders with 1-layer decoders—achieve high performance with fewer parameters, indicating efficient learning of numerical patterns.
- Empirical validation confirms that Wigner matrices’ eigenvalue standard deviation depends only on matrix dimension and coefficient variance, supporting theoretical predictions and enabling generalization.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.