Language Models Do Hard Arithmetic Tasks Easily and Hardly Do Easy Arithmetic Tasks (2024)

Abstract: The ability (and inability) of large language models (LLMs) to perform arithmetic tasks has been the subject of much theoretical and practical debate. We show that LLMs are frequently able to correctly and confidently predict the first digit of n -digit by m -digit multiplication tasks without using chain of thought reasoning, despite these tasks require compounding operations to solve. Simultaneously, LLMs in practice often fail to correctly or confidently predict the last digit of an n -digit by m -digit multiplication, a task equivalent to 1-digit by 1-digit multiplication which can be easily learned or memorized. We show that the latter task can be solved more robustly when the LLM is conditioned on all of the correct higher-order digits, which on average increases the confidence of the correct last digit on 5-digit by 5-digit multiplication tasks using Llama 2-13B by over 230% (0.13→0.43) and Mistral-7B by 150% (0.22→0.55).

## introduction the development of large language models (llms) @xcite has given new life to the deep learning revolution, and seen mass adoption within not just the scientific community, but also society at large. these llms, being the first known "general" machine learning model developed by humanity @xcite , have been applied to various tasks dealing with natural language such as those commonly encountered in school curricula @xcite , and even branching off into tasks such as text-to-image generation @xcite and hierarchical planning @xcite . despite the generality and far-reaching consequences of llms, there are still many significant limitations making difficult the direct application of llms to certain tasks. one such limitation is * correspondence: atgambardella@weblab.t.u-tokyo.ac.jp the poor performance of llms on arithmetic tasks, such as elementary addition, subtraction, multiplication, and division @xcite . not only do modern llms perform poorly on these tasks, but some tasks such as n-digit by m-digit multiplication and division, which require compounding operations to solve, appear to be unlearnable by pure autoregressive transformer architectures unless they decompose the problem into multiple steps, such as with chain of thought reasoning @xcite . as such, several solutions have been proposed, such as fine-tuning so that chain of thought reasoning is automatically used for problems which require compounding operations @xcite or fine-tuning to call outside tools, such as a calculator @xcite . while we most likely cannot expect simply training models with more parameters to allow for the solving of tasks which require compounding operations without chain of thought, we believe that analyzing the limitations and abilities of autoregressive llms when attempting to solve these tasks directly may shed light on unknown properties of llms. we therefore use monte carlo dropout (mc dropout) @xcite to analyze the performance of llms which were trained with dropout and which have open weights available, such as llama 2 @xcite and @xcite , in carrying out arithmetic tasks. mc dropout allows one to interpret neural networks which were trained with dropout as bayesian neural networks, as neural networks trained with dropout have been shown to be equivalent to a bayesian approximation to a gaussian process. this allows one to obtain empirical bayesian confidence distributions over neural network weights or outputs by doing multiple forward passes through the neural network with dropout on, during test time @xcite . mc dropout is one of many ensemble-based methods for uncertainty quantification @xcite , and has been applied to analyze the confidence of transformer architectures @xcite and to implement tree-based llm prompting @xcite . our results when applying mc dropout to llama 2 and mistral in arithmetic tasks were surprising. we found that all models could confidently and correctly predict the first digit result of n-digit by m-digit multiplication problems, despite it most likely being impossible for any autoregressive llm to have learned a general algorithm for doing so without decomposing the problem into multiple steps, as finding this digit in general requires solving the entire multiplication problem 1 . we also found that all models struggled to correctly output the last digit of n-digit by m-digit multiplication problems, despite it being very easy to learn an algorithm for doing so, as calculating the last digit is equivalent to 1-digit by 1-digit multiplication. finally, we show that the confidence of llms in predicting the last digit can be increased by conditioning the generation of the last digit on the correct intervening digits, despite the computation of the last digit not depending on the correct computations of the higher-order digits at all. ## experiments we evaluate the huggingface @xcite implementations of llama 2-7b, llama 2-13b, and mistral-7b @xcite in 2-shot settings, where the 2-shot examples are of correct n-digit by m-digit multiplications. sections 2.1 and 2.2 show results on the 3-digit by 3-digit multiplication task 592 * 392, and averages over multiple problems with varying digit length are provided in section 2.3. details about the prompt and hyperparameters are given in appendix a, details about the tokenizers for the models are given in appendix b, and details about the use of dropout in the training of the models is given in appendix c. ## conclusion here we present findings on the application of llms to arithmetic tasks, seen through the lens of monte carlo dropout. we found that the abilities of what llms can do in practice, versus what the theory dictates should be possible for llms to do, can be reversed in several cases. in particular, we found that llama 2 and mistral could confidently and correctly output the first digit of the result of ndigit by m-digit multiplication tasks despite most likely being unable to in the general case, whereas they struggled with outputting the last digit either correctly or confidently, a task which should be easily learnable. we also found that accuracy and confidence in outputting the last digit increases when the prior digits are correct, and we believe that this finding is related to, and could have implications for, recent results in hallucination detection.