Source-linked AI summary

Mastering Symbolic Operations: Augmenting Language Models with Compiled Neural Networks

Yixuan Weng, Minjun Zhu, Fei Xia, Bin Li, Shizhu He, Kang Liu, Jun Zhao

arXiv:2304.01665v3cs.CL

TL;DR

Language models remain limited on deterministic symbolic reasoning, and their performance can deteriorate as test length grows. Neural Comprehension integrates compiled neural networks with pretrained language models to encode rules explicitly. The paper reports strong symbolic-task results and symbolic-processing capabilities on par with tool-based methods across different model scales.

  • Problem

    Language models remain limited in deterministic symbolic reasoning and length generalization, with performance deteriorating as test length increases.

    Source: §1 · p. 1
  • Method

    Neural Comprehension combines a pretrained language model with compiled neural networks that explicitly encode rules through artificially generated attention weights.

    Source: §1 · p. 2
  • Results

    Neural Comprehension outperforms existing techniques in accuracy, efficiency, and interpretability, with symbolic-processing capabilities on par with tool-based methods across model scales.

    Source: §1 · p. 2
  • Takeaways & Limitations

    The neural-network framework provides symbolic manipulation without external interpreters and can give symbolic abilities to language models without coding capabilities.

    Source: §6 · p. 9

    Integration of tens of thousands of CoNN modules is described as theoretical potential rather than a demonstrated scale.

    Source: §5.4 · p. 9

Abstract

from arXiv · show

Language models' (LMs) proficiency in handling deterministic symbolic reasoning and rule-based tasks remains limited due to their dependency implicit learning on textual data. To endow LMs with genuine rule comprehension abilities, we propose "Neural Comprehension" - a framework that synergistically integrates compiled neural networks (CoNNs) into the standard transformer architecture. CoNNs are neural modules designed to explicitly encode rules through artificially generated attention weights. By incorporating CoNN modules, the Neural Comprehension framework enables LMs to accurately and robustly execute rule-intensive symbolic tasks. Extensive experiments demonstrate the superiority of our approach over existing techniques in terms of length generalization, efficiency, and interpretability for symbolic operations. Furthermore, it can be applied to LMs across different model scales, outperforming tool-calling methods in arithmetic reasoning tasks while maintaining superior inference efficiency. Our work highlights the potential of seamlessly unifying explicit rule learning via CoNNs and implicit pattern learning in LMs, paving the way for true symbolic comprehension capabilities.

1 INTRODUCTION

Language models still struggle with deterministic symbolic reasoning and length generalization, while relying on rules learned implicitly from text. The introduction presents Neural Comprehension as a plug-and-play integration of pretrained language models and compiled neural networks, with experiments reporting strong symbolic-task performance and applicability across model scales.

1 INTRODUCTION

  • As test length increases, language-model performance on addition deteriorates, illustrating difficulty with symbolic length generalization.The cited experiment evaluates addition tasks from 3 to 30 digits, with lengths above 10 digits out of distribution for training.Source: §1 · p. 1, Figure 1 · p. 1
  • The framework combines a pretrained language model with CoNNs that explicitly encode rules, enabling direct rule deduction without relying on conditional-probability learning.The authors describe CoNNs as human-controllable and integrate them in a plug-and-play manner.Source: §1 · p. 2
  • AutoCoNN uses language models’ contextual learning capabilities to automatically generate CoNNs and extend the framework to additional symbolic operations.The toolkit is presented as a means of making Neural Comprehension scalable.Source: §1 · p. 2
  • Neural Comprehension achieves flawless execution on symbolic reasoning tasks and outperforms existing techniques on symbolic and real-world arithmetic reasoning tasks.The authors also report advantages in accuracy, efficiency, and interpretability over learning-based methods.Source: §1 · p. 2
  • Neural Comprehension performs on par with tool-based methods across models from T5-Small (60M) to GLM-130B (130B) and GPT-3.5 (175B).The authors note that tool-based methods require code-generation capability and external interpreters.Source: §1 · p. 2
  • Adding correlated CoNNs can continuously improve performance, while adding uncorrelated CoNNs rarely degrades it.The authors present this as a possible approach to model fusion and acquiring new knowledge.Source: §1 · p. 2

2 RELATED WORKS

Related work describes symbolic reasoning as a persistent challenge for language models, alongside approaches based on prompting and external tools. These approaches offer possible routes to reasoning but have limitations in accuracy, computational demands, or integration.

2 RELATED WORKS

  • Language models primarily capture statistical patterns, and symbolic reasoning requires manipulating abstract symbols and rules and extrapolating to situations absent from training data.Prior work also reports that gradient learning constrains language models’ ability to solve symbolic problems wholly.Source: §2 · pp. 2–3
  • In-context learning and chain-of-thought prompting have been applied to numerical and symbolic reasoning, but can require substantial computation and still fall short of perfect accuracy.Examples include scratchpad prompting for length generalization and chain-of-thought arithmetic with single-digit carries.Source: §2 · p. 3
  • Augmented language models can use external tools such as Python for numerical reasoning, but this approach lacks a unified framework and relies on program generation.Source: §2 · p. 3

3 PRELIMINARIES

The preliminaries describe CoNNs as transformer-based networks that encode rules through compiled attention weights. Their Select, Aggregate, and Zipmap operations implement sequence transformations, illustrated with a parity task.

3 PRELIMINARIES

  • A CoNN uses artificially compiled attention weights in a transformer-based neural network to execute rules.It can stack attention and MLP layers to address human-defined rule problems, including mathematical calculations and symbol operations.Source: §3 · p. 3
  • CoNNs represent sequence-to-sequence processing through Select, Aggregate, and Zipmap operations.Select uses query-key interactions, Aggregate combines values, and Zipmap is handled by an MLP layer.Source: §3 · p. 3
  • In the parity example, Select obtains an all-ones matrix, Aggregate counts zeros and ones, and Zipmap determines whether the total is odd or even.Source: §3 · p. 3, Figure 2 · p. 3

4 METHOD

Neural Comprehension combines pretrained language models’ implicit learning with CoNNs that explicitly encode symbolic rules. Its method covers LM–CoNN integration, gradient modification, and automated CoNN construction.

4 METHOD

  • Neural Comprehension integrates language models’ implicit learning with CoNNs whose neural structures and weights directly encode symbolic rules.The framework is designed for deterministic execution of rule-based tasks.Source: §4 · p. 3

4.1 NEURAL COMPREHENSION

  • Predefined CoNNs gate rule-triggered sequence transformations, while LM context generation and CoNN outputs are fused through an expanded hidden-state matrix.The framework uses CoNN attention to calculate values for rule-required operations.Source: §4.1 · p. 4

4.2 GRADIENT MODIFICATION IN NEURAL COMPREHENSION

  • The framework combines implicit text-derived LM gradients with explicit rule-derived CoNN gradients to optimize in-context learning, though this decomposition is only approximate.The authors describe CoNN gradients as suited to rule-based tasks and the combined gradients as balancing implicit and explicit learning.Source: §4.2 · p. 5

4.3 AUTOCONN TOOLKIT

  • AutoCoNN prompts an LLM with instructions and examples to generate Tracr programs, converts candidates into PyTorch CoNNs, and filters them against examples.Parity, Reverse, Copy, and Last Letter CoNNs used in Section 5 were built with AutoCoNN.Source: §4.3 · p. 5

5 EXPERIMENTS AND RESULT

Across symbolic operations, symbolic reasoning, arithmetic reasoning, and module-combination experiments, Neural Comprehension is reported to improve rule-intensive performance. The experiments also examine its generalization, training behavior, tool comparison, and module scalability.

5.1 SYMBOLIC TASKS

  • Neural Comprehension achieves near-perfect symbolic operations across input lengths, while learning-based methods show distinct in- and out-of-distribution failure modes.Vanilla fine-tuning performs best on its 10–20-digit training range but deteriorates outside it; few-shot learning also remains weak above ten digits. Scratchpad and Algorithmic methods generalize robustly but require substantial computation and face input-length limits.Source: Table 1 · p. 6, §5.1 · pp. 6–7

5.2 SYMBOLIC REASONING

  • Neural Comprehension improves symbolic reasoning in most cases over vanilla fine-tuning and can fit faster, assessed through accuracy on intermediate-process outputs.The experiment represents intermediate processes in a Chain-of-Thought-like format to assess the rule-comprehension component.Source: §5.2 · p. 7, Figure 5 · p. 7

5.3 ARITHMETIC REASONING

  • On longer-digit arithmetic tasks, Neural Comprehension improves language-model performance over vanilla Chain-of-Thought using Addition and Subtraction CoNNs.The comparison includes AddSub+ digit-length variants and GSM8K-Hard addition, subtraction, and mixed subsets.Source: §5.3 · p. 8, Figure 6 · p. 8, Table 2 · p. 8
  • Compared with PAL-style tools, Neural Comprehension avoids extra programming and execution steps, remains end-to-end differentiable, and applies across model scales.The paper contrasts CoNNs' differentiability with tool-based methods' non-differentiability and notes that tools require large, code-trained models.Source: §5.3 · p. 8

5.4 ABLATION AND ANALYSES: MODULE COMBINATION FOR NEURAL COMPREHENSION

  • Combining pertinent CoNNs through plug-and-play gating bolsters performance, while unrelated modules rarely cause harm in single- or multiple-CoNN configurations.The experiments use Last Letter Concatenation and AddSub+; Figure 7 distinguishes task-related from unrelated CoNNs.Source: §5.4 · p. 9, Figure 7 · p. 9
  • Each CoNN has 1/1000 to 1/1000000 of GPT-3's parameters, and inference latency increases 1%-3% versus Vanilla.The paper attributes the limited interference from irrelevant modules to the framework's design for precise execution of assigned tasks.Source: §5.4 · p. 9
  • The framework is described as accommodating existing and novel knowledge concepts as the number of CoNN modules expands, with integration of tens of thousands presented as theoretical potential.The paper does not present tens-of-thousands-module integration as an experimental result.Source: §5.4 · p. 9

6 CONCLUSION

The conclusion presents Neural Comprehension as a plug-and-play integration of compiled neural networks into language models. It emphasizes symbolic manipulation without additional interpreters and gradient propagation without proxies.

  • Neural Comprehension integrates compiled neural networks into language models, enabling symbolic manipulation without additional interpreters and allowing gradients to propagate without proxies.The conclusion presents this as a foundation for unifying implicit and explicit learning in language models.Source: §6 · p. 9

A DISCUSSION OF LIMITATIONS AND FUTURE WORK

The discussion identifies limits in integrating and scaling CoNNs and proposes adding explicit knowledge; the accompanying material explains CoNNs and illustrates rule-based symbolic operations.

A DISCUSSION OF LIMITATIONS AND FUTURE WORK

  • The framework uses separate sparse LM and CoNN modules, has been tested with at most five stacked CoNNs, and leaves larger-scale combinations unclear.The discussion also identifies more efficient and natural integration as an unresolved limitation.Source: A DISCUSSION OF LIMITATIONS AND FUTURE… · p. 16
  • The discussion proposes compiling explicit knowledge, potentially using knowledge graphs, into CoNNs that currently encode rules.The authors suggest this could improve interpretability and knowledge representation and potentially broaden task performance.Source: A DISCUSSION OF LIMITATIONS AND FUTURE… · p. 16

B.1 INTRODUCTION

  • CoNNs are transformer-inspired networks for tasks including computer arithmetic and linear algebra, with operations explicitly represented by specialized attention and MLP weights.RASP abstracts transformer components into select, aggregate, and zipmap primitives; Tracr compiles RASP programs into transformer weights that can be converted to PyTorch.Source: §B.1 · p. 17, B COMPILED NEURAL NETWORKS · p. 17

B.2 EXAMPLE

  • The example section describes representing computations as transformer code and obtaining new CoNN weights with the Tracr compiler.Source: §B.2 · p. 17

B.2.1 PARITY CONN

B.2.2 REVERSE CONN

  • Reverse CoNN processes either word tokens such as “hello” and “world” or individual letters, with figures showing its hidden states and output.One illustrated character-level input is “reverse.”Source: §B.2.2 · p. 18, Figure 10 · p. 19, Figure 11 · p. 19

B.2.3 ADDITION CONN

  • Addition CoNN separates same-position addition from carry calculation, then repeats the carry model for the input length; this implementation supports natural numbers only.The hidden-state transformation is omitted because of the model’s complexity, though code is provided for implementation.Source: §B.2.3 · pp. 18–19

B.2.4 SUBTRACTION CONN

  • Subtraction CoNN subtracts corresponding digits and then handles carry, supporting natural-number cases only when the minuend exceeds the subtrahend.Source: §B.2.4 · p. 19

B.3 CONN MODEL PARAMETERS

The section contrasts CoNN parameter sizes with GPT-3 and describes potential environmental and human-centric benefits of compiled networks.

B.3 CONN MODEL PARAMETERS

  • Table 3 is described as reporting parameter sizes for single-function CoNNs and comparing them with GPT-3.Source: Table 3 · p. 21
  • CoNNs need only a small number of parameters to solve symbolic problems, while the section compares a single-function CoNN’s parameter size with GPT-3.The supplied text does not give the table’s parameter values.Source: §B.3 · pp. 19, 21, Table 3 · p. 21

B.4 ENVIRONMENTAL AND HUMAN-CENTRIC BENEFITS OF COMPILED NEURAL NETWORKS

  • The authors state that reducing pretraining and parameter size can lower energy use and emissions, and that explicit operations make CoNN reasoning more interpretable and transparent.They connect interpretability with scrutiny of model behavior, trust, and human-AI collaboration.Source: §B.4 · p. 21

C.1 METHOD

AutoCoNN uses language models’ few-shot ability to address the effort of creating CoNN code. The section reports faster generation, difficulty with addition and subtraction, and validation guidance for generated models.

C.1 METHOD

  • AutoCoNN can generate various CoNNs faster than experts, but it failed to generate working models for the more difficult addition and subtraction tasks.The comparison concerns expert working time and AutoCoNN generation results.Source: §C.1 · p. 21, Table 5 · p. 22
  • When generating CoNN code, explicit instructions often produced higher accuracy than examples alone.The experiments used sampling at temperature 0.7 to generate 20 candidate codes, which experts manually evaluated.Source: §C.1 · pp. 21–22
  • Validation with two examples was generally sufficient to select an accurate CoNN, though the authors recommend more examples because task difficulty varies.The validation checks whether model outputs exactly match the examples.Source: Table 4 · p. 21, §C.1 · p. 22

D EXPERIMENTAL SETTINGS

The experiments cover symbolic operations, symbolic reasoning, and arithmetic reasoning. A separate T5-large study finds that increasing in-distribution training data yields only marginal out-of-distribution gains.

D EXPERIMENTAL SETTINGS

  • The evaluation spans symbolic operations (parity, reverse, addition, subtraction), symbolic reasoning (last-letter concatenation, coin flip), and arithmetic reasoning datasets.The arithmetic evaluation includes AddSub, SingleEq, MultiArith, GSM8K, SVAMP, and a new AddSub+ dataset with operations ranging from 1 to 20 digits.Source: D EXPERIMENTAL SETTINGS · p. 22

E.1 THE EFFECT OF TRAINING DATA SCALE ON LENGTH GENERALIZATION OF GRADIENT-BASED MODELS

  • For the training-scale study, T5-large was trained on 10-to-20-digit numbers while the number of in-distribution examples varied from 1 million to 15 million.Peak validation performance for each experiment is reported in Figure 12.Source: §E.1 · pp. 22–23, Figure 12 · p. 23
  • Increasing in-distribution training data led to only marginal out-of-distribution performance improvements in the T5-large length-generalization study.The study varied training examples from 1 million to 15 million and reports peak validation performance in Figure 12.Source: §E.1 · pp. 22–23, Figure 12 · p. 23

E.2 REAL-WORLD ARITHMETIC REASONING TASKS

The section evaluates Neural Comprehension on real-world arithmetic tasks, reports inference-latency trade-offs, and describes the models and experimental setups used.

E.2 REAL-WORLD ARITHMETIC REASONING TASKS

  • Neural Comprehension with Addition and Subtraction CoNNs improved performance over Vanilla CoT across several arithmetic tasks, although gains were limited by the selected CoNN models.The comparison is reported for problem-solving rates on arithmetic reasoning datasets.Source: §E.2 · p. 23, Table 6 · p. 24
  • On GSM8K, comparisons across three T5 model sizes indicate that Addition and Subtraction CoNNs model human-defined deterministic rules, avoiding uncertainty from gradient-descent learning on data distributions.Table 7 reports test-set problem-solving rates for T5 models on GSM8K.Source: §E.2 · p. 24, Table 7 · p. 24

E.3 THE EFFICIENCY OF NEURAL COMPREHENSION

  • Adding CoNNs increases computational requirements, while the proportion of δTime progressively diminishes as pretrained language models grow, particularly for larger models.The section compares inference latency for Vanilla and Neural Comprehension T5 models; full results are identified as Table 8.Source: §E.3 · pp. 24–25, Table 8 · p. 24

F IMPLEMENTATION AND DETAILS

  • The experiments use T5, GPT, and GLM-130B models; the framework supports decoder-structure language models across scales, with T5 fine-tuned and models above 10 billion parameters evaluated few-shot.The implementation section frames its setup description as supporting repeatability.Source: §F.1 · p. 25, F IMPLEMENTATION AND DETAILS · p. 25

F.1.1 FINE-TUNING

  • T5 fine-tuning uses standard preprocessing, batch size 64, Adafactor at 1 × 10−4, up to 20 epochs, cosine scheduling, and 0.1 dropout; selection avoids OOD test performance.The reported validation accuracy increased during training and no overfitting was observed in the experiments described.Source: §F.1.1 · p. 25, Table 10 · p. 25

F.1.2 FEW-SHOT IN-CONTEXT LEARNING

  • GPT and GLM-130B few-shot prompts use natural-language input-output examples; API-constrained Neural Comprehension comparisons simulate gating by correcting generated output with CoNNs left to right.The simulation feeds the adjusted response back into the API for continued generation.Source: §F.1.2 · p. 26

F.2 TASKS AND DATASET

The section describes dataset construction for length-generalization, synthetic arithmetic and symbolic tasks, and arithmetic reasoning, then identifies examples illustrating the framework across task groups.

F.2 TASKS AND DATASET

  • Length-generalization datasets use separate sets with the same digit counts but different lengths, and unique test-set digits; this design can produce slight fluctuations across lengths.The text says the overall trend remains generally clear.Source: §F.2 · p. 26

F.2.1 DATA GENERATION DETAILS

  • Synthetic parity and reverse datasets cover lengths 1–40; the described experiments train on lengths 10–20, while addition examples use randomly generated numbers and subtraction follows a similar approach.The parity experiment uses 99,000 training samples per bit and 1,000 test samples per bit; reverse training uses 99,000 samples at each length 10–20.Source: §F.2.1 · pp. 26–27

F.2.2 SYMBOLIC REASONING DATASET

  • The symbolic dataset includes coin-flip sequences represented in English-like sentences and last-letter concatenation requiring extraction and concatenation of names’ final letters.Both descriptions specify 1,500 training samples; coin flip tests use 100 non-overlapping samples for each of 2–4 flips, while last-letter tests cover name lengths 2–4.Source: §F.2.2 · p. 28

F.2.3 ARITHMETICAL REASONING DATASET

G SOME EXAMPLES OF NEURAL COMPREHENSION

G.1 SYNTHETIC SYMBOLIC

G.2 SYMBOLIC REASONING

G.3 ARITHMETICAL RESONING

  • The arithmetic-reasoning examples are presented in a separate table.Source: Table 18 · p. 31
Loading 2304.01665v3…