Large language model with exact arithmetic

By integrating a symbolic architecture like OccamNet with LLMs to perform arithmetic, the method addresses computational inefficiencies and errors in LLMs, enhancing accuracy and security in mathematical sequence generation.

WO2025250446A1PCT designated stage Publication Date: 2025-12-04MASSACHUSETTS INST OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
PCT/US2025/030707
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-05-29
Filing Date
2025-05-23
Publication Date
2025-12-04

AI Technical Summary

Technical Problem

Existing large language models (LLMs) struggle with accurate arithmetic computations, leading to errors and increased computational time, especially when generating sequences that require mathematical reasoning, and external tools like calculators introduce security vulnerabilities and data limitations.

Method used

Integrate a symbolic architecture, such as OccamNet, with the LLM to perform arithmetic computations, using the LLM's hidden states to control the symbolic architecture, and selectively choose between LLM and symbolic outputs to generate accurate sequences.

Benefits of technology

This approach reduces computational time and errors, providing faster and more secure arithmetic capabilities by leveraging the LLM's reasoning with a symbolic model, achieving high accuracy in mathematical tasks without external tool reliance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure US2025030707_04122025_PF_FP_ABST
    Figure US2025030707_04122025_PF_FP_ABST
Patent Text Reader

Abstract

Exact and interpretable computation is integrated into a large language model (LLM)- based generative process using an LEM in combination with a symbolic architecture that performs arithmetic, or other mathematical or domain-specific processing. Hidden states of a ELM are processed to control this symbolic architecture, and inputs to the symbolic architecture are automatically extracted from already generated words. A selection is made during an autoregressive generative process as to whether to use the ELM output or the output of the symbolic architecture to extend the word sequence. Because the use of the symbolic architecture is part of the autoregressive process, the computed result is incorporated into the generation of future words in the result. Advantages of this approach include reduced computation and higher accuracy, for example, by avoiding arithmetic or computation errors manifested in the generated word sequence.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] LARGE LANGUAGE MODEL WITH EXACT ARITHMETIC

[0002] CROSS-REFERENCES TO RELATED APPLICATIONS

[0003] This application claims the benefit of U.S. Provisional Application No. 63 / 653,179, filed on May 29, 2024, which is incorporated herein by reference.

[0004] STATEMENT AS TO FEDERALLY SPONSORED RESEARCH OR DEVELOPMENT

[0005] This invention was made with government support under PHY2019786 awarded by the National Science Foundation, and FA8750- 19-2- 1000 by the Air Force Office of Scientific Research. The government has certain rights in the invention.

[0006] BACKGROUND OF THE INVENTION

[0007] This invention relates to design and use of a large language model that implements exact arithmetic.

[0008] As used herein, a “language model” is a computational system that processes and / or generates sequences of items from a vocabulary. For ease of exposition, these items are referred to as “word” or “tokens”, and the vocabulary is, for example, a list of English language words. Some models can evaluate a given sequence to determine if it meets a specified criterion, such as forming a proper English language sentence, or can provide a probability of its occurrence in a domain of usage. For example, the sentence “The Dow Jones Industrial closed down 10% from yesterday’s open of 41,953 to 37,758.” is much more likely to be found in a newspaper domain than a sentence starting with “The Dow Jimmy Industrial . . .”. Furthermore, the sentence ending in “37,758” is much more likely than a sentence ending with a miscalculation such as “46,148” (i.e., a miscalculation increasing rather than decreasing the value, or even a minor error such as “38,778”).

[0009] Some language models are used to generate sequences from the vocabulary, for example generating a random valid sequence, possibly as a random sample from a probability distribution of sequences. Such language models are referred to as “generative language models.” Typically, the generated sequence depends on an input, which may be referred to as a “prompt” or a “context.”

[0010] Some generative language models compute successive words in a sequence based on the partial word sequence that precedes the new word. For example, if the previous words were “The Dow”, the next word might, for example, be “Industrial”, “close”, or “fell.” Such models may be referred to as “generative autoregressive language models” to denote that future words in the sequence depend on the previous words in the sequence.

[0011] Some generative language models depend on an input, for example, a prompt word sequence, which may be considered to be an initial word sequence that is extended by the language model. For example, a prompt might be “How did the Dow do yesterday?”.

[0012] Some language models are referred to as being “large,” as in “large language model” or “LLM”. This denotation does not necessarily characterized by a particular technology used for the language model, and rather connotes the sheer number of parameters (which may be referred to as “weights” for certain model technologies). Certain large language models today have in the order of a trillion (1012) parameters.

[0013] Language models are typically configured to represent sequences that arise in a particular domain, and therefore may generate sequences that mimic that domain. In the case of LLMs, the domain may be huge, for example encompassing almost all text that is accessible over the Internet. The method of configuring a language model is referred to as “training.” In the case of language models that internally use artificial neural networks (ANNs), the training amounts to adjusting the weights to best match the collective characteristics of the training data.

[0014] A language model that respond to prompts by extending the word sequence may appear to have the ability to reason. Some systems today incorporate explicit reasoning aspects that are used to augment the language model’s ability to reasonably. For instance, in response to the prompt “What is 3 plus 1?” the language model may extend the sequence as “What is 3 plus 1? The sum of 3 and 1 is 4.” Having generated the partial sequence ending in “. . . 3 and 1 is”, a child can tell you that then next word should be “4”, and indeed LLMs generally have been trained on a sufficient number of sentences to have essentially built in addition tables in some manner in their trained weights. As another example, the partial sequence may be “Alice has 6 apples and 7 oranges. How many pieces of fruit does she have? In total she has”, and the next word that should be generated is “13”.

[0015] On the other hand, in another example introduced above, if an LLM is extending the word sequence “. . .closed down 10% from yesterday’s open of 41,953 to”, the LLM may not have sufficient capacity to correctly produce the next word “37,758” and it may make an arithmetic error. Such errors are more prevalent in smaller language models that have relatively less capacity to incorporate mathematical knowledge in their weights. Some LLMs are specifically trained on mathematics problems, thereby increasing their capacity to output word sequences that do not represent arithmetic errors, but such specific training may limit the general applicability of the LLM.

[0016] To enable accurate calculations, language model systems may resort to having the LLM generate software code and then executing the code to yield a response. However, this comes at the cost of speed; the model must perform multiple autoregressive steps to generate code that performs the appropriate arithmetic operations. This increased decoding time may negatively impact applications such as multi-agent workflows where speed is essential. At the same time, code-based LLM arithmetic mechanisms may increase system vulnerability by providing a mechanism for arbitrary LLM-generated code execution.

[0017] Another thrust of prior research has focused on LLM tool use, for example, to offload arithmetic computations to an external tool like a calculator rather than generating and executing computer code. In one such approach, the output of the LLM includes tags to signify the calling of the external tool. A number of such tool-based approaches are limited by the training data required, including human annotated training data.

[0018] SUMMARY OF THE INVENTION

[0019] In one aspect, in general, exact and interpretable computation is integrated into an LLM-based generative process, thereby providing faster and more secure arithmetic capabilities. The approach makes use of an LLM in combination with a symbolic architecture that performs arithmetic, or other mathematical or domain- specific processing. Hidden states of a LLM are processed to control this symbolic architecture that performs arithmetic, and inputs to the symbolic architecture are automatically extracted from already generated words. A selection is made during an autoregressive generative process as to whether to use the LLM output or the output of the symbolic architecture to extend the word sequence. Because the use of the symbolic architecture is part of the autoregressive process, the computed result is incorporated into the generation of future words in the result. The approach can be used with an arithmetic network that computes arithmetic functions of its inputs. Advantages of this approach include reduced computation (e.g., number of instructions required to generate a sequence and / or fewer LLM parameters) and also provides higher accuracy by avoiding arithmetic or computation errors manifested in the generated word sequence.

[0020] In another aspect, in general, an apparatus comprising a natural language generator.

[0021] This natural language generator comprises an autoregressive large language model (LLM) and a computational model coupled to the LLM. The LLM is configured to receive a prior sequence of N-l tokens from a vocabulary, and to generate an Nth token. The computational model is configured to receive values of internal state of the LLM from generation of said Nth token, determine one or more arguments represented in the sequence of N-l tokens, and compute a result of a computation with the one or more arguments as inputs and based at least in part on the internal state of the LLM. The natural language generator further includes a selector coupled to the LLM and the computation model to select from among inputs comprising the Nth token generated by the LLM and the result of the first computation computed by the computational model as an extension of the prior sequence. The natural language generator is configured to repeat extension of sequences using the LLM and the computation model such that at least one token in a resulting sequence is a result of the computational model.

[0022] Aspects can include one or more of the following features.

[0023] The computational model comprises an arithmetic network that is configurable to perform any one of a plurality of numerical computation on numerical inputs.

[0024] The computational model is further configured to select the first computation from a plurality of computations based at least in part on the internal state of the LLM.

[0025] The arithmetic network implements a directed graph representation of a numerical computation in which nodes represent functions, and links in the graph represent flow of arguments and results of said functions.

[0026] The computational model comprises a decoder configured to process the internal state of the LLM and to provide configuration values to the arithmetic network to configure it to perform the first computation.

[0027] The computational model comprises a decoder configured to process the internal state of the LLM and to provide a control signal to the selector to determine the selection from among its inputs.

[0028] The computational model comprises at least one of a parser and a transformer-based model configured to process the sequence to identify the one or more arguments represented in the sequence.

[0029] The result of the computation computed by the computation model yields multiple successive tokens in the resulting sequence.

[0030] The autoregressive large language model comprises a transformer-based model.

[0031] The computational model implements at least one of an arithmetic computation, a symbolic transformation, a rule-based function, and a data lookup. In another aspect, in general, a method for natural language generation comprises generating an output sequence of tokens by repeatedly extending a partial sequence. The process at each repetition includes using an autoregressive large language model (LLM), that receives a prior sequence of N-l tokens from a vocabulary, and generates an Nth token. A computational model is coupled to the LLM, and receives values of internal state of the LLM from generation of said Nth token. The computational model determines one or more arguments represented in the sequence of N-l tokens, and computes a result of a first computation with the one or more arguments as inputs and based at least in part on the internal state of the LLM. The internal stated of the LLM is used to select from among inputs comprising the Nth token generated by the LLM and the result of the first computation computed by the computational model as an extension of the prior sequence. At least one token in the output sequence is a result of the computational model, and that token is part of the prior sequence for at least one repetition.

[0032] Other features and advantages of the invention are apparent from the following description, and from the claims.

[0033] BRIEF DESCRIPTION OF THE DRAWINGS

[0034] FIG. 1A-B are block diagrams of an autoregressive large language model;

[0035] FIG. 2 is a block diagram of an autoregressive large language model with an arithmetic model;

[0036] FIG. 3 is a block diagram of an alternative embodiment of an autoregressive large language model with an arithmetic model;

[0037] FIG. 4 is a block diagram of an implementation of the arithmetic model of FIG. 2;

[0038] FIGS. 5A-B are diagrams of a computational structure in an arithmetic network;

[0039] DETAILED DESCRIPTION

[0040] Referring to FIG. lA,an LLM-based system 100 has an autoregressive large language model (LLM) 110, which is shown in the process of generating the N'hword WN 112 based on the previous N -l words W1 through WN-1 112. After this Nth word is generated, it is appended to the sequence, and as shown in FIG. IB, the A + T' word is generated in the same manner. The LLM 110 may be a large multi-layer transformer-based language model, such as GPT-4. As introduced above, as examples, the N - 1 words may represent the partial sequence “What is 3 plus 1? The sum of 3 and 1 is” and the Nthword should be the word “4”, or may represent “ . . . How many pieces of fruit does she have? In total she has” and the Nth word should be “13”.

[0041] Referring to FIG. 2, in one embodiment of the presented approach, an arithmetic model 210 is introduced into an LLM-based system 200, while the LLM 110 remains the same as in FIGS. 1A-B. As used herein, an “arithmetic” computation should be understood to mean a numerical computations that are made up of fundamental operations such as addition, subtraction, division, and multiplication, and certain other functions such as exponentiation. In addition, other functions, such as trigonometric functions including sine or cosine, may be included in the computation and the overall computation would still be referred to herein as “arithmetic.” In FIG. 2, the arithmetic model receives the words in the partial sequence, as well as internal state 212 of the LLM 110 and produces two outputs. One output is a word output 214, which is a prediction by the arithmetic model of what the next word (or words) should be, and the second output is a selector output 216, which indicates a certainty that the word generated by the arithmetic network should be used. The selector output is provided to a switch 220, which either picks the Nth word determined by the LLM or else pick the word generated by the arithmetic model. Therefore, the arithmetic model 210 can effectively override the autoregressive generation by the LLM of a next word, and otherwise, the combination of the LLM 110, the arithmetic model 210 and the switch 220 together function as an autoregressive language model or system. Note that after having overruled the generation of the Nth word with one generated by the arithmetic model, that Nth word is what is appended to the previous word sequence and used for generation by the LLM of the N + 1 ” word.

[0042] Before continuing with a description of the arithmetic model 210 shown in FIG. 2, a somewhat more general embodiment of this approach is shown in FIG. 3. In this embodiment, rather than merely overruling the Nth word being generated, the entire new N-word sequence make be edited by a switch / editor 320 at the command of the arithmetic model. The switch 220 of FIG. 2 is an example of such a switch / editor in which the first N- 1 words are left unchanged.

[0043] Referring to FIG. 4, an implementation of the arithmetic model 210 shown in FIG. 2 includes a decoder 410, a parser 420, and an arithmetic network 430. For each new output word being generated by the LLM 110, the corresponding internal hidden states 212 of the LLM 110 are fed into the decoder 410, which initializes the arithmetic network 430 such that it executes the operation required by the task described in the partial sequence of words prior to the current word being generated. A parser 420 interprets the partial word sequence to locate the arguments (e.g., numbers) for the computation to be performed by the arithmetic network, and feeds the arguments from the text into arithmetic network, which evaluates the desired expression and output the word (or words) 214 representing that evaluated answer. Finally, the decoder determines whether to use the LLM output or the arithmetic network output for generating the next word by providing the selector output 216.

[0044] In the example introduced above in which the partial word sequence “Alice has 6 apples and 7 oranges. How many pieces of fruit does she have? In total she has” and the desired Nth word is “13” the decoder 410 determines how to initialize arithmetic network 430 from the language model hidden states 212, in this example configuring the arithmetic network to perform addition of two input arguments. The parser 420 extracts the numbers 6 and 7 from the partial word sequence and feeds them into arithmetic network. The arithmetic network adds the numbers yielding an evaluated result of 13, which it provides as its output 214. Finally, the decoder 410 decides to use the arithmetic network output instead of the language model output, so the switch 220 outputs 13 from the arithmetic network as the next output word. The new sentence, including the 13, fed back to the LLM to continue autoregressive generation. The language model might later generate “Since she ate two apples, she now has,” at which point arithmetic model 210 might implementing 13 minus 2 and return 11.

[0045] One example of an arithmetic network is OccamNet, which is a symbolic architecture that provides an interpretable way of parametrizing probability distributions over a space of functions. This network is described in detail in Dugan et al. “OccamNet: A fast neural model for symbolic regression at scale” arXiv preprint arXiv:2007.10784 (2020). This paper is incorporated herein by reference.

[0046] A I -layer OccamNet with primitives P and n inputs is an architecture that defines a probability distribution over the space of functions representable as compositions of the primitives in P up to depth I . For example, a two-layer OccamNet with primitives P = { sin, cos } and one input represents a probability distribution over the set P = {x, sin(x), cos(x), sin(sin(.r)), sin(cos(.r)), cos(sin(.x)), sin(sin(.r)) }

[0047] OccamNet has the structure of an n -input, I -intemal-activation-layer multilayer perceptron with the biases removed and the activations in each layer replaced by the primitives P, as shown in FIG. 5A. Activation functions may have multiple inputs. We rename the linear layers softmax layers, denote the weights of the i th softmax layer as W0}, and denote the combined weights of OccamNet as W.

[0048] Referring to FIGS. 5A-B, a schematic of the OccamNet architecture has softmax layers in light lines and their outputs in filled circles. A Directed Acyclic Graph (DAG) (with edges not connected to the output removed for clarity) shown in FIG. 5B is formed by sampling from OccamNet. This DAG of FIG. 5B corresponds to the function sinlsinCx!) exp(x0)). We define the probability distribution which OccamNet parametrizes by specifying how to sample from it. For each softmax layer output node (shown in filled circles in FIGS. 5A-B), we select a single connection to that node from a softmax layer input node by sampling from the distribution given by the softmax of the weights of the connections to the different inputs. This process produces a directed acyclic graph (DAG) defining a computational path through the OccamNet activations, such as the one shown in FIG. 5B. In this way, each DAG represents a function of the inputs of OccamNet.

[0049] To ensure that OccamNet can represent all possible compositions of functions in P up to depth 1, we include the following modifications to the OccamNet architecture: 1) for each softmax layer, we concatenate its inputs with the previous softmax layer’s inputs to enable the representation of functions with fewer than I compositions, and 2) we repeat primitives in the; th activation layer Al~‘ times, where A is the maximum number of inputs of any of the primitives, to ensure that a sufficient number of each primitive is available at each layer. We refer to this modified architecture as “complete OccamNet” as it can represent the complete set of desired functions.

[0050] In principle, approach described above can work with any arithmetic network that implements a symbolic model, i.e., any model that can parameterize a set of symbolic functions or a distribution over such functions. The choice of OccamNet as opposed to, for example, a transformer or recurrent neural network has two advantages: 1) OccamNet is interpretable, which we hypothesize makes controlling OccamNet an easier task for a decoder to learn, and 2) OccamNet is parallelizable over multiple samples, allowing for scalable training.

[0051] As introduced above, the decoder 410 as illustrated in FIG. 4 has two outputs: one (412) going to the arithmetic network (e.g., OccamNet), and one (216) going to the switch. The decoder may be implemented as a deep neural network (DNN) with two outputs, or it may be implemented as two separate networks, or there may be some shared parts and some separate parts, for example, with initial layers of a neural network being shared, and then separate parts generating the outputs separately. Furthermore, while the parser 420 and the decoder 410 are illustrated as separate components, they may indeed have shared elements. In the description of the decoder for the OccamLLM embodiment described below, the decoder 410 has separate parts, which are trained separately from one another.

[0052] One part of the OccamLLM decoder takes the hidden states of a LLM 110 and outputs an initialization for OccamNet implementation of the arithmetic model 210 in the form of weights of the connections within the arithmetic network. For example, the LLM may be a layered transformer model The hidden states of the LLM can include the values passing between layers of the LLM, and optionally can include values internal to one or more of the layers. For example, a GPT 3.5 model may have close to 100 transformer-based layers (e.g., each implementing an attention mechanism), and the hidden values between those layers are what are used to initialize the arithmetic model. In some implementations in which the LLM is a layered model, the internal state may include values within layers as well as values passing between layers.

[0053] Using the internal state gives the LLM control over which function to apply on the inputs. The decoder acts repeatedly as the word sequence is extended, using a different OccamNet initialization for each word. Therefore, the arithmetic operations predicted may change along an input sequence, allowing OccamNet’ s use for different computations in a single generated word sequence. This is very important in multi-step reasoning scenarios where OccamNet is employed several times for different purposes.

[0054] Referring again to FIG. 4, many architectures for the decoder 410 are possible. We choose to parameterize the weights of each softmax layer of OccamNet independently, as ( W(1), . . . , W(Z)) = (Decoder! (h), . . . , Decoder, (h)), where h are the hidden states of the language model. We choose

[0055] Decoder, ( where h are the hidden states of the j th layer of the language model, w, . are trainable weights, MLP, are two-layer multilayer perceptrons (MLPs), and W’(,)are untrained weights which initialize all functions to have approximately equal probabilities according to the initialization scheme described in the OccamNet paper cited above.

[0056] We similarly train a decoder for a switch 220 that, for each input token, is fed the hidden states of the language model and selects whether to use the output of arithmetic network or the output of the language model. The decoder outputs a single number from 0 to 1, where all numbers less than or equal to 0.5 correspond to using the output of the language model and all numbers greater than 0.5 correspond to using the output of the arithmetic network. We choose the following architecture for the switch decoder:

[0057] Decoderswitch(h) = sigmoid

[0058] Training of the decoder 410 makes use of synthetic datasets, which contain instruction prompts for diverse arithmetic tasks. To generate datasets of arbitrary size, we create prompts with placeholders for numbers. Each prompt includes a question with number placeholders, the sampling value range for each number, and a function that computes the answer to the query given the sampled input numbers. The prompts fall into two main categories: purely arithmetic tasks and reasoning problems.

[0059] Purely arithmetic prompts are formed by expressions including only symbols, without any natural language added, such as “3 + 85 =”. We create prompts using the following operations: +(•,•) , -(•,•) >x(-, ) , +( ) , sqrt(-) , power(-, ) , loge( ) , exp( ) , sin(-) , and cos(-) .

[0060] We also include word problems that require one or two reasoning steps. We generated 150 single step word problems and 40 multi-step reasoning problems which we modified from examples in the MultiArith training dataset (see Roy el al. “Solving general arithmetic word problems.” arXiv preprint arXiv: 1608.01413 (2016)).

[0061] For training the decoder that controls the weights of OccamNet, we created two types of examples, single queries and concatenated queries. For single queries, we select a single prompt from the problems generated as discussed above. We use the Llama 3 Instruct chat template and fill in the query as the user input and the result as the assistant response, prepending "Answer = " to the later in randomly selected samples. For the concatenated queries of examples, we select a random number of prompts and concatenate the queryresponse pairs without using the Llama 3 Instruct chat template. The decoder is trained to predict only the results of the last query in the sequence. This strategy helps the system to learn which operation to perform without becoming confused by earlier text, which is useful for continuous generation. To create the training dataset, each example is sampled by first randomly selecting whether to create a single or concatenated query, then randomly selecting the type(s) of prompt(s) used, and finally randomly sampling the input values from the range corresponding to each selected prompt.

[0062] To train the switch, we generate examples of possible LLM outputs for given input expressions and label the outputs with sequences of 0s or Is corresponding to whether the language model or the arithmetic network output should be used for the next token. Some examples correspond to the prompts described above. For such examples, the LLM output is set to “The answer is” or “Answer = “ and the label sequence is all 0s with a 1 at the last token to indicate the system should use the arithmetic network only to compute the answer. We also manually created and labeled several other examples for diverse scenarios to explicitly teach the system in which cases it should or should not use the arithmetic network. To create the training dataset, we concatenate a random number of the above user input - assistant output pairs in a conversational fashion, using the Llama 3 Instruct chat template.

[0063] We train the decoder 410 and the switch separately, as they do not share weights. In all cases, the weights of the LLM 110 are kept frozen. In the first step, we train the system to predict the answer to examples generated by the method explained above. The decoder processes the hidden states corresponding to the last token of the response and sets the weights of arithmetic network such that the correct arithmetic expression is sampled. In this step, we use a rescaled REINFORCE loss, which can also be interpreted as a Monte- Carlo estimate of the cross-entropy loss: where pw[f] = ON( / ; Decoder,v(h(x))) is the probability distribution represented by the decoder-initialized OccamNet.

[0064] Minimizing this loss steers the decoder towards assigning higher probabilities to the functions that maximize the reward R(f(x), y) , which measures the similarity between the correct answer y and the prediction of OccamNet / (x) . We find setting R( / (x), y) = l if f (x) = y , and 0 otherwise, most effective..

[0065] The second step involves training the decoder to route the outputs to OccamNet when needed. We train the switch decoder alone, freezing the weights of the OccamNet decoder of the previous step and minimizing the binary cross-entropy loss between the switch output and the desired output for each token. The OccamLLM switch decoder learns when to route the output to OccamNet in diverse contexts.

[0066] Experimental results were generated for the OccamNet embodiment described above. We use Meta’s Llama 3 8B Instruct and Llama 3 70B Instruct as the underlying LLM 110 In these experiments, we use a 1 layer Complete OccamNet with primitives sqrt(-), power(-, •), loge(-), exp(-), sin(-), cos(-) } .

[0067] This single layer OccamNet can be invoked by the LLM several times during generation to perform complex arithmetic operations accurately. To use the trained OccamLlama for inference, we sample the highest probability function from OccamNet.

[0068] We benchmark our methods against unmodified Llama 2 7B Chat (Llama 2 7B), unmodified Llama 3 8B Instruct (Llama 3 8B), gpt-3.5-turbo-0125 (GPT 3.5 Turbo), gpt- 4o-2024-05-13 (GPT 4o), and gpt-4o-2024-05-13 with Code Interpreter (GPT 4o + Code). To reduce costs, for GPT 4o with Code Interpreter, we test a random subset of 200 datapoints for each dataset.

[0069] To determine if a model output is correct, we parse all numbers in the model output and if one of them “matches” the correct answer, we determine that the result is correct. We mark each correct result as 100% accuracy and each incorrect result as 0% accuracy. For each model on each dataset, we report the mean accuracy and the standard error of the mean.

[0070] To determine if a number matches the result, we first determine how many places after the decimal $c / S the number should be accurate to. If the number is an integer, we set d to 2. Otherwise, we set d to the number of places after the decimal in the model output, clipped between 2 and 5. Finally we state that a number “matches” the result if the number and the result differ by less than I O '7.

[0071] To evaluate OccamLlama and the baselines on purely arithmetic expressions, we create several synthetic datasets. For each of the operations in {+, x, -F} , the inputs are random 7-digit positive or negative integers. For , the inputs are random 7-digit positive integers. For the logarithms, the examples are log-uniformly sampled in the interval (10 ' 1 ()'") ; for the exponentials, they are uniformly sampled in the interval (-10,10) , and for sines and cosines they are uniformly sampled in the interval (-2^, 2TF) .

[0072] The results of these evaluations are shown in the following Table:

[0073] Both OccamLlama 8B and 70B have 100.0 ± 0.0 % accuracy on all tasks, missing 0 out of 9000 problems. On the other hand, we tested GPT 4o with Code Interpreter on fewer problems to save cost, and it missed 3 out of the 1800 problems it faced, achieving an accuracy of 99.8 ± 0.1 %. Furthermore, GPT 4o with Code Interpreter generates on average more than 54 tokens to answer these problems, whereas our model uses OccamNet on the first forward pass. This means that, barring advanced decoding techniques such as speculative decoding, GPT 4o would need to be more than 50x faster than OccamLlama per forward pass to be comparable in answer generation speed on these tasks.

[0074] To test the performance of OccamLlama on more general mathematical problem solving tasks, we evaluate our method and baselines on the following six benchmarks: AddSub, GSM8K, MultiArith, MATH401, Single Eq, and SVAMP. All but MATH401 are word problems requiring longer generation and a mix of reasoning and arithmetic capabilities. MATH401 also includes multistep arithmetic problems which require more than one call to OccamLlama. We selected these datasets (including the MultiArith Float dataset described below) before testing any methods on them to ensure unbiased selection of benchmarks.

[0075] Because many of the arithmetic operations required in these datasets are relatively simple, we also create MultiArith Float, a modification of MultiArith in which we select problems which are arithmetically more challenging, while requiring similar levels of reasoning. To this end, we select prompts having input numbers that can be replaced with floats. For instance, 3.5 feet or $39.95 are reasonable but 3.5 people is not. Furthermore, we sample input values from ranges larger than those appearing in the MultiArith dataset, in cases where it is reasonable. Float operations and larger additions and multiplications are more difficult for the baseline LLMs but do not make a difference for OccamLLM, so this dataset is particularly useful to show the advantages of the system we propose.

[0076] OccamLlama 70B outperforms both GPT 4o and GPT 4o + Code on average across the benchmarks, demonstrating OccamLlama's strong mathematical problem solving capability. We also note that GPT 4o + Code does not outperform GPT 4o on average, suggesting that existing implementations of LLMs with code generation may not help with mathematical problem solving.

[0077] We now consider the performance of OccamLlama 8B, the smaller OccamLlama model. On MultiArith Float and MATH401, two datasets requiring challenging arithmetic, OccamLlama 8B outperforms not only Llama 3 8B but also GPT 4o and GPT 4o + Code.

[0078] At the same time, most other datasets in this benchmark do not involve challenging arithmetic, meaning that Llama 3 8B is well suited to solve these tasks without assistance; most of the difficulty of these tasks lies in the reasoning rather than in the arithmetic computations. This is further supported by the fact that GPT 4o with Code Interpreter never substantially outperforms and sometimes underperforms GPT 4o on these tasks. As such, it is remarkable that OccamLlama 8B can achieve comparable accuracy to Llama 3 8B even when it is trained on very different data and evaluated on tasks without challenging arithmetic.

[0079] The only datasets for which OccamLlama 8B performs noticeably worse than Llama 3 8B are GSM8K and Single Eq, but we believe this results from an imperfect OccamLlama switch, likely stemming from text which is outside of the switch training. Fortunately, we find that the OccamNet decoder is quite robust to out of distribution data and that both the OccamNet and switch decoders generalize well to unseen languages. This suggests that, with relatively little data, it should be possible to teach the switch to handle these unseen cases, something we leave for future work.

[0080] In the table below, we show example generations from OccamLlama 8B for both arithmetic and reasoning tasks. These generations demonstrate how the OccamLlama switch learns to balance OccamNet outputs with LLM outputs, effectively distributing the work between a reasoner (Llama) and a calculator (OccamNet). Because the language model is unaware of the OccamLlama system, its generations behave as if it possesses an interior calculator even though it is actually using a tool. In this way, we combine the benefits of a language model finetuned on arithmetic with the benefits of a language model finetuned to use code for arithmetic, all without any finetuning.

[0081] Examples from Llama 3 8B Instruct and OccamLlama 8B on (top) an arithmetic problem and (bottom) a mathematical reasoning problem from the MultiArith Float dataset. In OccamLlama, the LLM performs reasoning, the switch predicts when to use OccamNet, and OccamNet performs arithmetic operations.

[0082] In experiments described above, we use a single-layer OccamNet as the symbolic network, enabling evaluation of single-operation arithmetic problems. This sometimes poses a challenge on reasoning problems when the base language model generates compound expressions requiring more than one operation to evaluate, such as 3 + 5 + 7 = . A single-layer OccamNet cannot evaluate these expressions. We attempted to overcome this by prompting Llama to break down compound expressions into multiple steps, but we find it difficult to coerce Llama to follow these instructions. Another challenge is that Llama often generates expressions in fractions or percentages, which also constitute compound expressions that are not properly handled by the OccamLLM system. Fortunately, we observed that these compound expressions were typically simple enough for the LLM to evaluate without OccamNet. Therefore, in our experiments, we trained the OccamLLM switch to avoid using OccamNet for compound operations, largely mitigating this issue. Future work could explore other solutions such as integrating a two-layer OccamNet as the symbolic network. We found that these issues are particularly acute in the GSM8K and Single Eq datasets, where the expressions generated by Llama are not prevalent in the switch training data, causing it to sometimes incorrectly trigger OccamNet and degrade performance.

[0083] We found that the language model sometimes appends further digits to OccamLlama outputs, defeating the purpose of OccamLlama generations. To address this issue, we append \n\n.” to every number computed with OccamNet, emulating the usual behavior of Llama.

[0084] In alternative embodiments, other tools beyond calculators are integrated through a similar technique. This is facilitated by the fact that there are no restrictions on OccamNet' s activations; in principle, tools could be placed inside activations of OccamNet, enabling OccamNet to serve as a sort of a mixture of experts for tools. While some tools, like querying a search engine, may still be most effective when integrated into language model systems through language, other tools are more effective when they can be more tightly integrated into the language model.

[0085] Further details regarding experimental results and training approaches are found in Provisional Application 63 / 653,179 and in Dugan, Owen, Donato Jimenez-Benetd, Charlotte Loh, Zhuo Chen, Rumen Dangovski, and Marin Soljacic. "OccamLLM: Fast and Exact Language Model Arithmetic in a Single Step." Advances in Neural Information Processing Systems 31 (2024): 35665-35699, which are incorporated herein by reference.

[0086] In an embodiment described above, the approach makes use of OccamNet. However, it can also work with other symbolic architectures such as the EQL network (Martins et al. “Extrapolation and learning equations,” arXiv e-prints, page arXiv:1610.02995, October 2016; Sahoo et al., “Learning equations for extrapolation and control.” In Jennifer Dy and Andreas Krause, editors, Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research, pages 4442—4450, Stockholmsmassan, Stockholm Sweden, 10—15 Jul 2018. PMLR), or architectures that can represent probability distributions over symbolic expressions, such as transformers (Ashish Vaswani et al., “Attention Is All You Need,” arXiv e-prints, page arXiv:1706.03762, June 2017) or recurrent neural networks (RNNs).

[0087] Regarding transformers and RNNs, OccamNet possesses a key advantage of being interpretable; simply by looking at the weights, it is possible for a human to determine which functions OccamNet assigns a high probability. We believe that this interpretability will make OccamNet easy for a decoder to initialize with the desired distribution. On the other hand, an RNN or transformer have substantially more complex relations between the weights and corresponding probability distribution, which we hypothesize would make learning a decoder for such models difficult. This leads us to a key point: transformers and RNNs are effective for modeling complex multimodal distributions, but for this problem, we want to select a single function for each token, so the extra expressivity of these models is unneeded and likely detrimental to performance. OccamNet, with a much simpler architecture, enables better parameter efficiency and performance.

[0088] Returning to the nature of the autoregressive generation of a natural language word sequence, as introduced, such a sequence may be represented using a sequence of “tokens” that are not necessarily words. In some systems, such tokens are parts of words. For instance, the tokens may include word stems and word endings. As another example, the tokens may be letter sequences that are selected according to their frequency of occurrence (e.g., chosen using a version of a byte-pair encoding approach). In such cases, the arithmetic network may generate a normal word, which is transformed into a sequence of one or more tokens. Therefore, while the LLM may generate a single token at a time, when the system selects use of the output of the arithmetic model, for example, “37,758”, a token sequence “37”, “75”, “8” may be added to the previously generated tokens.

[0089] There are various alternative structures for the parser 420, which locates the arguments for the arithmetic model. One approach is a pattern matching approach, as might be implemented using a regular expression or other grammar, that processes the words, and in the case of the arithmetic computation, locates numbers in the word sequence (e.g., “53”, “fifty three”) and processes then by rule to yield numerical (e.g., binary encoded integer or floating point) representations. Yet other approaches may be used, including transformer- (e.g., Bidirectional Encoder Representations from Transformers (BERT)) based processing of the words, rather than rules or a grammar, to find the endpoints of the arguments.

[0090] As introduced above, the approach is not limited to arithmetic processing. For example, other domain-specific models may be used to process parts of an input to yield an output that is specific to the domain. For example, a model may be used to perform algebraic (i.e., symbolic) transformations rather than numerical calculations, or may perform rule-based or data lookups functions, such as looking up in an electrical wiring code the required gauge of a wire based on the length of a run and a current capacity, rather than using a graph-based computation.

[0091] While the examples described above are in the context of generation of natural language, it should be recognized that LLM-based generative approaches are used in other domains. For example, representations of chemical or protein structures may use LLMs. In such examples, a computational network may be used to augment the LLM, for example, to predict next tokens in a manner that may not be easily learned in training of the LLM. For instance, the added network may predict a next token (e.g., an atom in a chemical formula) based on a domain specific rule.

[0092] A number of implementations of the approaches described above can be used. For instance some or all of the processing may be performed under the control of software instructions. The instructions may include instructions for special-purpose processors, such as Graphics Processing Units (GPUs) or Tensor Processing Units (TPUs) or the like, which are particularly adapted to performing neural network computations as found in an LLM, or in the decoder described above. In some cases, some of the instructions may be performed on special-purpose processors, while other instructions may be performed by general purpose processors, such as on a Central Processing Unit (CPU). For example, the arithmetic network may be implemented on a CPU while the LLM may be implemented on a GPU. The data processing system implementing the approach will in general include memory for the configurations of the components, working memory that is used during the generation, and input / output components for communicating with a user of the system or other computational systems. For example, input / output components provide a user interface (e.g., a graphical or text interface on a computer or network-based display) for a user to provide a natural language prompt (e.g., a question) and for the system to provide a natural language response to the prompt using the approached described herein. A number of embodiments of the invention have been described. Nevertheless, it is to be understood that the foregoing description is intended to illustrate and not to limit the scope of the invention, which is defined by the scope of the following claims. Accordingly, other embodiments are also within the scope of the following claims. For example, various modifications may be made without departing from the scope of the invention. Additionally, some of the steps described above may be order independent, and thus can be performed in an order different from that described.

Claims

WHAT IS CLAIMED IS:

1. An apparatus comprising a natural language generator, comprising: an autoregressive large language model (LLM), said model being configured to receive a prior sequence of N-l tokens from a vocabulary, and to generate an Nthtoken; a computational model coupled to the LLM, and configured to receive values of internal state of the LLM from generation of said Nthtoken, determine one or more arguments represented in the sequence of N-l tokens, compute a result of a computation with the one or more arguments as inputs and based at least in part on the internal state of the LLM; and a selector coupled to the LLM and the computation model to select from among inputs comprising the Nthtoken generated by the LLM and the result of the first computation computed by the computational model as an extension of the prior sequence; wherein the natural language generator is configured to repeat extension of sequences using the LLM and the computation model such that at least one token in a resulting sequence is a result of the computational model.

2. The apparatus of claim 1, wherein the computational model comprises an arithmetic network that is configurable to perform any one of a plurality of numerical computation on numerical inputs.

3. The apparatus of claim 2, wherein the computational model is further configured to select the first computation from a plurality of computations based at least in part on the internal state of the LLM.

4. The apparatus of claim 2, wherein the arithmetic network implements a directed graph representation of a numerical computation in which nodes represent functions, and links in the graph represent flow of arguments and results of said functions.

5. The apparatus of claim 2, wherein the computational model comprises a decoder configured to process the internal state of the LLM and to provide configuration values to the arithmetic network to configure it to perform the first computation.

6. The apparatus of claim 2, wherein the computational model comprises a decoder configured to process the internal state of the LLM and to provide a control signal to the selector to determine the selection from among its inputs.

7. The apparatus of any one of claims 1 through 6, wherein the computational model comprises at least one of a parser and a transformer-based model configured to process the sequence to identify the one or more arguments represented in the sequence.

8. The apparatus of any one of claims 1 through 6, wherein the result of the computation computed by the computation model yields multiple successive tokens in the resulting sequence.

9. The apparatus of any one of claims 1 through 6, wherein the autoregressive large language model comprises a transformer-based model.

10. The apparatus of any one of claims 1 through 6, wherein the computational model implements at least one of an arithmetic computation, a symbolic transformation, a rule-based function, and a data lookup.

11. A method for natural language generation comprising generating an output sequence of tokens by repeatedly extending a partial sequence, including at each repetition: using an autoregressive large language model (LLM), receiving a prior sequence of N- 1 tokens from a vocabulary, and generating an Nth token; using a computational model coupled to the LLM, receiving values of internal state of the LLM from generation of said Nth token, determining one or more arguments represented in the sequence of N-l tokens, computing a result of a first computation with the one or more arguments as inputs and based at least in part on the internal state of the LLM; andusing the internal stated of the LLM, selecting from among inputs comprising the Nth token generated by the LLM and the result of the first computation computed by the computational model as an extension of the prior sequence; wherein at least one token in the output sequence is a result of the computational model, and wherein said one token is part of the prior sequence for at least one repetition.

12. The method of claim 11, wherein the computational model comprises an arithmetic network that is configurable to perform any one of a plurality of numerical computation on numerical inputs, and computing the first result comprises performed a first number computation of the plurality of numerical computations.

13. The method of claim 12, wherein the computational model is further configured to select the first computation from a plurality of computations based at least in part on the internal state of the LLM, and using the computational model further comprises selecting the first computation from the plurality of computations.

14. The method of claim 12, wherein the arithmetic network implements a directed graph representation of a numerical computation in which nodes represent functions, and links in the graph represent flow of arguments and results of said functions, and computing the result comprises applying a data flow procedure using the directed graph.

15. The method of claim 12, wherein the computational model comprises a decoder configured to process the internal state of the LLM and to provide configuration values to the arithmetic network to configure it to perform the first computation, and using the computation model comprises configuring the artithmetic model according to the internal state of the LLM.

16. The method of claim 12, wherein the computational model comprises a decoder configured to process the internal state of the LLM, and using the computation model comprises providing a control signal from the decoder to the selector to determine the selection from among its inputs.

17. The method of any one of claims 11 to 16, wherein the computational model comprises at least one of a parser and a transformer-based model and determining the one or more arguments comprises processing the sequence with the parser or the transformer-based model to identify the one or more arguments represented in the sequence.

18. The method of any one of claims 11 to 16, wherein the result of the computation computed by the computation model yields multiple successive tokens in the resulting sequence.

19. The method of any one of claims 11 to 16, wherein the autoregressive large language model comprises a transformer-based model.

20. The method of any one of claims 11 to 16, wherein the computational model implements at least one of an arithmetic computation, a symbolic transformation, a rule-based function, and a data lookup.

21. A non-transitory machine readable medium comprising instructions stored thereon, said instructions when executed by a data processing system cause said system to perform all the steps of any one of claims 11 to 20. application (1)

Citation Information

Patent Citations

  • Using Chains of Thought to Prompt Machine-Learned Models Pre-Trained on Diversified Objectives

    US20230244938A1

  • Computer implemented methods for the automated analysis or use of data, including use of a large language model

    US20230274086A1