NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Recursion in Recursion: Two-Level Nested Recursion for Length Generalization with Scalability

Jishnu Ray Chowdhury, Cornelia Caragea

Abstract

Recursive Neural Networks (RvNNs) are highly effective for tasks requiring structural reasoning and length generalization, yet they traditionally lack the scalability necessary for long-sequence processing. Conversely, models like Transformers and Structured State Space Models (SSMs) scale efficiently but often fail to capture complex hierarchical dependencies. We present Recursion in Recursion (RIR), a framework that nests a dynamic Beam Tree RvNN within a scalable $k$-ary balanced tree. RIR achieves the structural depth of recursive models with the logarithmic complexity of balanced trees. Experiments demonstrate that RIR achieves over 90% length generalization on the ListOps task and competitive performance on the Long Range Arena (LRA) benchmark, while significantly reducing memory overhead compared to traditional RvNNs.

Introduction

A persistent challenge in sequence modeling is the trade-off between computational scalability and structural reasoning. Standard RvNNs are designed for hierarchical data, enabling them to learn rules on short sequences and apply them to significantly longer ones. However, their linear or super-linear scaling with sequence length makes them impractical for long-range tasks. Modern architectures like Transformers and SSMs excel at processing long sequences but struggle with "structure-sensitive" tasks, such as logical inference or code analysis, where hierarchical nesting is paramount. Even balanced-tree RvNNs, which offer logarithmic scaling, often fail because they impose a rigid, predefined structure that may not align with the underlying logic of the input. RIR bridges this gap by combining the best of both worlds.

The RIR Framework

The Recursion in Recursion (RIR) framework resolves the tension between scalability and reasoning through a two-level nested architecture:

  1. Outer Recursion: The model utilizes a $k$-ary balanced tree as a structural skeleton. This ensures that the total depth of the computation remains $\log_k n$, providing the necessary scalability for long sequences.
  2. Inner Recursion: Rather than using a static cell function at each node, RIR employs a powerful Beam Tree RvNN to process each chunk of $k$ elements. This inner model dynamically searches for the optimal local tree structure using beam search, allowing for flexible and data-dependent structural reasoning.

Technical Innovations

To integrate these two levels effectively, the framework introduces two critical mechanisms:

  • Beam Alignment: This stochastic sampling strategy ensures that high-scoring structural hypotheses (beams) from one level of recursion are successfully propagated to the next, maintaining structural diversity without sacrificing performance.
  • Pre-Chunk Processing: To prevent the "broken context" problem—where a logical unit is split across two chunks—a bidirectional S4D (Structured State Space) layer is used to provide global context to tokens before they enter the recursive chunking process.

Experimental Evaluation

RIR was evaluated across several benchmarks designed to test both structural reasoning and long-range scalability:

  • ListOps-O: A diagnostic task for hierarchical processing, tested on both near-IID (similar length) and OOD (unseen lengths and argument counts) splits.
  • Logical Inference: Assessing the model's capacity for formal propositional logic.
  • Long Range Arena (LRA): Testing on Text, Retrieval, and ListOps tasks with sequences up to 2,000 tokens.
  • Standard NLP Tasks: Including SST5, IMDB, QQP, and SNLI/MNLI to verify general-purpose utility.

Results and Discussion

RIR demonstrates a significant breakthrough in balancing efficiency and reasoning:

  • Length Generalization: RIR-EBT-GRC achieved 99.72% accuracy on near-IID ListOps and maintained approximately 97% accuracy on sequences significantly longer than those encountered during training. This confirms that explicit recursive inductive biases are essential for certain types of reasoning.
  • LRA Performance: RIR outperformed Transformers by a substantial margin on language tasks and remained competitive with SSMs. Crucially, it was the only model capable of solving the logic-heavy ListOps tasks within the LRA suite.
  • Efficiency: RIR reduced the memory footprint of the original Beam Tree RvNN by hundreds of times. Empirical tests showed it to be multiple times faster and more memory-efficient than previous structure-aware models like Ordered Memory (OM).

Conclusion

The RIR framework proves that recursive inductive biases can be implemented at scale. While RIR is currently slower than pure SSMs or Transformers due to the overhead of the inner recursive loop, it offers a unique solution for tasks requiring deep structural intelligence. Future research may focus on optimizing the inner cell implementation or dynamically adapting the chunk size $k$ based on input complexity.

Summary updated

BibTeX
@inproceedings{chowdhury2023recursion,
  author = {Jishnu Ray Chowdhury and Cornelia Caragea},
  title = {{Recursion in Recursion: Two-Level Nested Recursion for Length Generalization with Scalability}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=o6yTKfdnbA},
}
Figure