Abstract
Feed-forward neural networks consist of a sequence of layers, in which each layer performs some processing on the information from the previous layer. A downside to this approach is that each layer (or module, as multiple modules can operate in parallel) is tasked with processing the entire hidden state, rather than a particular part of the state which is most relevant for that module. Methods which only operate on a small number of input variables are an essential part of most programming languages, and they allow for improved modularity and code re-usability. Our proposed method, Neural Function Modules (NFM), aims to introduce the same structural capability into deep learning. Most of the work in the context of feed-forward networks combining top-down and bottom-up feedback is limited to classification problems. The key contribution of our work is to combine attention, sparsity, top-down and bottom-up feedback, in a flexible algorithm which, as we show, improves the results in standard classification, out-of-domain generalization, generative modeling, and learning representations in the context of reinforcement learning.
Introduction: The Modularity Gap in Deep Learning
In traditional feed-forward neural networks, each layer acts as a monolithic block that takes the entire hidden state of the previous layer as its input. This rigid structure lacks the modularity found in standard computer programming, where well-defined functions operate only on a specific, small set of relevant variables (arguments). Because standard neural layers must process everything at once, they struggle to specialize, isolate errors, or dynamically route information.
Furthermore, most feed-forward architectures are strictly bottom-up. They lack the top-down feedback mechanisms—using higher-level context to inform lower-level processing—that are prevalent in human cognition and highly useful for handling occluded images or shifting data distributions. While architectures like ResNets and DenseNets allow layers to access earlier states, these connections are rigid and static, rather than dynamically chosen based on the input.
Neural Function Modules (NFMs)
The authors propose Neural Function Modules (NFMs) to bring the flexibility of programming functions into deep learning.
Core Components
- Sparse Dynamic Arguments: Instead of just taking the immediate previous layer as input, an NFM uses its current state as a query to attend over all previously computed modules. It uses a multi-head top-$k$ softmax attention mechanism. This forces the module to select only a sparse subset of previous layers as its "arguments," mimicking how a programming function only takes a few specific variables.
- Multi-Pass Execution for Top-Down Feedback: To enable top-down feedback, the network is run forward multiple times ($K$ passes). During the second pass, an NFM can attend to layers computed during the first pass. Since the first pass has already processed the entire input into high-level representations, attending to it provides valuable top-down context.
- Automatic Type Conversion (Rescaling): If an NFM attends to a layer with a different spatial dimension, it automatically rescales the data. It uses a
SpaceToDepthoperation for downsampling or nearest-neighbor for upsampling, allowing modules of different sizes to seamlessly communicate.
Key Insights
- Programming as a Blueprint: By forcing layers to act like functions with sparse arguments, networks naturally develop better separation of concerns. Modules become highly specialized for specific sub-tasks rather than acting as generic, entangled feature extractors.
- Dynamic Routing: Unlike DenseNets, which rigidly concatenate all previous layers of the same size, NFMs dynamically decide which previous layers to read from based on the specific input. This allows the network to adapt its computation graph on the fly.
- Robustness through Feedback: The multi-pass architecture allows higher-level, compressed representations to inform lower-level feature extraction. This top-down context is especially valuable for recognizing partially occluded objects.
Experimental Results
The authors evaluated NFMs across a wide variety of domains, including image classification, generative modeling (GANs), relational reasoning, and reinforcement learning.
- Image Classification: NFM provided consistent improvements across standard benchmarks. For instance, CIFAR-10 accuracy rose from 96.27% to 96.56% on PreResNet18. More impressively, when tested on images with artificial occlusion boxes, NFM maintained 84.11% accuracy compared to the baseline's 82.46%.
- Generative Adversarial Networks: Integrating NFMs into the generator of an InfoMax-GAN significantly improved image quality, dropping the Frechet Inception Distance (FID) on CIFAR-10 from 15.12 to 13.15.
- Relational Reasoning: On the Sort-of-CLEVR dataset, NFM improved relational question accuracy from 68.26% to 74.95%. It also vastly outperformed standard CNNs and Relation Networks when tested on held-out, out-of-distribution color-shape combinations.
- Reinforcement Learning: When added to the encoder of a Rainbow IQN agent, NFMs substantially improved scores on 4 out of 5 tested Atari games (e.g., Q-bert scores jumped from 27,433 to 33,253).
Limitations and Future Work
The multi-pass setup ($K \ge 2$) increases computational cost and memory footprint during both training and inference. Ablation studies also showed that performance drops drastically if the learned attention routing is randomized at test time, indicating the model's high dependence on these learned paths. Future work includes integrating NFM modules with Transformer architectures and exploring non-sequential layer processing paradigms.
Summary updated