Search

Search papers and lessons

MRKL Systems: A Modular, Neuro-Symbolic Architecture

Ehud Karpas, Omri Abend, Yonatan Belinkov et al. · 2022

MRKL routes each request to specialist modules, such as a calculator or database, and falls back to a language model. A 7-billion-parameter model learns to hand arithmetic to a calculator.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

MRKL, pronounced "miracle", is a design for AI systems built from a language model plus a set of specialist modules. A router reads each request and sends it to the module best suited to answer it: a calculator for sums, a database for customer records, a currency service for exchange rates. If nothing fits, the request goes to the general language model. The authors also show, for basic arithmetic, that a 7-billion-parameter model can learn to pull the numbers and operation out of a sentence so that a calculator does the sum, reaching near-perfect accuracy on the tested cases.

Builds on: Tool Use, In-Context Learning, Data Augmentation · Leads to: LLM Agent, Toolformer: Language Models Can Teach Themselves to Use Tools

Why it mattered

The paper gave a name and a clear architecture to an idea that later systems use widely: a language model should not answer everything from memory, but should call outside tools for facts that change and for calculations it cannot do reliably. The authors' own system, Jurassic-X, was built by AI21 Labs as a MRKL system and piloted with partners. Modern assistants that call a calculator, a search engine or a code runner follow the same pattern: a router decides, a specialist computes, and the language model turns the result into text. The paper also set out the problem that the router has to solve, which is extracting exact arguments from free text, and it measured how well that can be trained. Later work on learning to call tools and on interleaving reasoning with actions addresses the same question from other directions. Retrieval-based systems, which fetch documents before answering, apply the same idea to knowledge that changes.

The problem

The authors start from a plain list of weaknesses of large language models (LMs) such as GPT-3 and their own Jurassic-1. Four matter here.

  1. Stale knowledge. An LM learns from a fixed set of text. Exchange rates, stock prices and the current date are not in it, and the model cannot update them by reading more text.
  2. No private data. A model has no access to a company's client list or the state of a game.
  3. Weak calculation. GPT-3 and Jurassic-1 handle two-digit addition well, but give confident wrong answers on four-digit addition. More training helps, but the authors do not expect it to match a calculator.
  4. Model explosion. Fine-tuning a model for each task gives good results on that task and loses versatility. Multi-task training on over 100 tasks helps on tasks close to the training set, but performance drops on tasks far from it, and adding a new task means retraining on everything. Serving many large fine-tuned models is also impractical.

The authors' answer is to keep the big language model, and add a set of separate modules that are easy to extend. The thing that is hard in this design is not the modules themselves. It is the handoff: a neural router must turn a sentence into the exact inputs a symbolic module needs.

How it works

A MRKL system has three parts: a set of experts, a router, and the general language model. Here is one request through the system.

flowchart LR
  U[User request] --> R{Router}
  R -->|arithmetic| C[Calculator]
  R -->|live data| A[API or database]
  R -->|no match| L[General language model]
  C --> O[Answer]
  A --> O
  L --> O

Take the request "How much is three minus one?" as a tiny trace. The numbers are small on purpose.

  1. Input arrives. The text is "How much is three minus one?" It goes to the router first, because the router decides which expert should handle it. Check: the text contains a subtraction word, so an arithmetic expert is the likely match.
  2. The router chooses a module. It picks the calculator, since the request is an arithmetic question. Choosing a module is a neural decision, since the paper treats the router as a specialised neural network. Check: if the request had been about a stock price, the router would choose the API module instead.
  3. The router extracts arguments. This is the step the paper studies in detail. The router must produce the operation and operands the calculator needs: subtraction, with operands 3 and 1. Check: the calculator needs exactly two numbers and one operation, nothing more.
  4. The calculator computes. It returns 2. The language model does not do the sum itself; it only chooses the arguments. Check: 3 minus 1 is 2.
  5. The answer is returned. The system outputs "2", and the module's output is the reason for the answer. The paper calls this a side benefit: the answer comes with a rationale, "because the calculator said so". Check: if the extraction had been wrong, for example addition instead of subtraction, the calculator would still return a correct sum, but the answer would be wrong. This is why the paper measures extraction accuracy and not calculator accuracy.

The paper gives six benefits of this design over fine-tuned multi-task models: a safe fallback to the general model when no module matches; robust extensibility, because each expert is trained on its own and only the router needs retraining; interpretability through the module's output; up-to-date information through APIs; access to proprietary data; and compositionality, where a multi-step request is split across experts.

The math

The system is a function that maps text to a module and a set of arguments, and then to an answer. Write the input text as xx. The router chooses a module mm from a finite set M\mathcal{M} of experts, plus the language model as a fallback, and produces arguments aa:

(m,a)=R(x),m∈M,y=m(a).(m, a) = R(x), \qquad m \in \mathcal{M}, \qquad y = m(a).

Here yy is the final answer, RR is the router and m(a)m(a) is the module run on its arguments. For the calculator, aa is a triple (an operation and two operands), and m(a)m(a) is the arithmetic result.

The paper measures the router by accuracy on a test set of NN problems:

accuracy=#{problems where the router gives the correct operation and operands}N.\text{accuracy} = \frac{\#\{\text{problems where the router gives the correct operation and operands}\}}{N}.

Because the calculator is exact, every error in this measure comes from the router. The authors make this point explicitly.

For the trained model, the paper uses prompt tuning: a fixed model with 10 learned prompt vectors placed before the input. Only the prompt vectors are trained, so the base model's weights stay fixed. The training settings reported are a learning rate of 0.3 with linear decay, a batch size of 32, and, for most experiments, weight decay of 0.001 and selection of the best checkpoint on a validation set.

Results

Generalising to longer numbers (Table 1). A model trained only on one-digit addition and multiplication was tested on one- to nine-digit problems. Addition scored 1.0 at every length. Multiplication scored 1.0 at every length except 0.98 at six digits. GPT-3 results taken from the original paper were 1.0 at two digits, 0.804 at three, 0.255 at four and 0.093 at five.

Words versus digits (Table 2). A model trained on digits and tested on digits scored 1.0, and one trained on words and tested on words scored 0.988. Training on words and testing on digits gave 0.987. Training on digits and testing on words gave only 0.156. The authors read this as a difference in how a number is represented (digits and words are tokenised differently), not as a failure of the arithmetic.

Phrasing (Table 3). Training on one question format and testing on five formats gave near-perfect results for addition, subtraction and multiplication. Division ranged from 0.997 on the training format to 1.0 on several others. The one format that is not a question, format 4, was hardest: 0.993 for addition, 0.863 for subtraction, 0.977 for multiplication and 0.727 for division, with large standard deviations for subtraction (0.237) and division (0.465).

Between operations (Table 4). Training and testing on the same operation gave at least 0.993 on the diagonal. Training on addition also transferred well: 0.96 to subtraction and 0.97 to multiplication. Division did not transfer. A model trained on division scored 0.787 on addition, 0.31 on subtraction and 0.23 on multiplication.

Two operations (Table 5). Trained on 14 of the 29 two-operation patterns, the model was tested on the other 15 over ten random splits. In 22 of the 29 patterns the average accuracy exceeded 0.9. The weakest pattern was f=((A+B)×C)f = ((A+B) \times C), at 0.288 on average.

Operation composition (Table 6). Trained only on single operations and tested on two-operation problems without brackets, the model did well in most pairs. The exceptions were addition followed by multiplication (0.01), subtraction followed by multiplication (0.202) and subtraction followed by division (0.224). The authors note that these three templates are phrased with two prefix phrases, such as "the sum of 2 and the product of 4 and 8".

Limits. The experiments use one model size, one language and a template-generated set of problems. The paper reports only accuracy on the tested arithmetic cases, not on open-ended routing, and it does not measure the cost of the system in production. The authors leave the routing problem itself, and the design of the full Jurassic-X system, for separate work.

Reading guide

Read the paper in this order. Each section depends on the prerequisites listed.

  • Section 1 (Introduction). Needs Tool Use for the idea of an external tool, and Catastrophic Forgetting for why retraining a multi-task model on a new task is costly. The "model explosion" argument also uses Fine-Tuning.
  • Section 2 (Jurassic-X). A short description of the system. Nothing new is needed beyond the introduction.
  • Section 3.1 (Arithmetic as a test case). Needs Tool Use to see why the handoff from text to a symbolic procedure is the hard part.
  • Section 3.2.1 (Data augmentation). Needs Data Augmentation: templates generate many training examples from a small structured space, and each example varies operand format, digit count, operation and brackets.
  • Section 3.2.2 (Experimental setup). Needs In-Context Learning for the contrast with the few-shot baseline. The method used here is prompt tuning, which is a trained soft prompt rather than examples in the text.
  • Section 3.2.3 (Results). Needs Few-Shot Learning to read the comparison with GPT-3 and to see why the few-shot setting is a baseline.
  • Appendix A (Few-shot vs prompt tuning). Compares ten in-context examples with the trained prompt. Needs In-Context Learning and Few-Shot Learning.

Check yourself

QuestionIn one sentence, what does the router do in a MRKL system, and what happens when no expert matches a request?Show answer

The router reads a request and chooses the module best suited to answer it, and it also produces the arguments that module needs. If no expert matches, the request goes to the general-purpose language model, which is the system's safe fallback.

QuestionTable 1 lists GPT-3 at 0.255 accuracy for four-digit addition. A model trained on one-digit operands scores 1.0 on the same task. By how many percentage points is the MRKL model ahead?Show answer

The gap is 1.0 minus 0.255, which is 0.745. So the MRKL model is ahead by 74.5 percentage points on that task.

QuestionWhy does the paper measure the router's accuracy, not the calculator's, when judging the arithmetic result?Show answer

The calculator computes exactly, so a wrong final answer can only come from a wrong operation or wrong operands passed to it. Measuring the router isolates the part of the system that is learned and can fail.

QuestionA user asks the system for the price of a share. Using the MRKL design, which expert should handle the request, and why would the language model alone be a poor choice?Show answer

The router should send it to a live data module such as an API, because share prices change and the language model learned from a fixed set of text. The language model alone would answer from stale training data, and it has no access to the current price.

Sources

Read the full paper

Ehud Karpas, Omri Abend, Yonatan Belinkov et al., 2022. arXiv:2205.00445