This post goes beyond sequences for representation learning and reasoning.
The multimodal Transformer models discussed in the previous 2 posts, Multimodal Transformers -part 1 and Multimodal Transformers -part 2, all share one common characteristic: they all started out processing multimodal inputs as a flat sequence of token embeddings, , allowing inputs from different modalities to attend to one another simultaneously.
However, this also prompts the question whether every element in a multimodal sequence really needs to attend to every other one.
This post discusses 3 types of hierarchical structures: graph structure, tree structure, and modular structure, exploring how they build domain knowledge directly into the model, using tools such as graph neural networks, syntactic parse trees, and neural module networks.
Graphs naturally arise in many real-world domains, such as social networks, economic networks, biomedical networks, and web networks. This section focuses on representation learning on undirected graphs.
Formally, a graph $G$ is described by a set of vertices $V$, a binary adjacency matrix $A$, a matrix of node features $X$, and an optional vector of node labels $Y$. The key idea behind Neighborhood-aggregation Encoder Algorithm for learning node representations in an undirected graph neural network is to recursively build each node's embedding from its local neighborhood. In this way, each node defines its own computation graph for learning its embedding.


These node embeddings can then be trained end-to-end for a supervised classification task, where the loss is computed as the sum of the cross-entropy losses between each node's output embedding, passed through a linear layer, and its corresponding ground-truth class label

Language also carries its own built-in structure in the form of syntax, and that structure can guide multimodal reasoning directly. Learning to Compose and Reason with Language Tree Structures for Visual Grounding proposes Recursive Grounding Tree (RvG-TREE) to jointly process a sentence and an image for visual grounding tasks, which aim to localize the region in the image referred to by a natural language sentence.
For natural language input, such as "skis of man in red jacket" , the model filters out all the determiners such as “a, an, another, any, both, each, either, those, that” in the sentence and then learns to compose a binary tree over the remaining terms.
For visual input, the model uses a region-based object detector to generate region proposals from the image.
Finally, the nodes of the syntax binary tree are recursively grounded with the proposed image regions. This allows the model to ground language in an image by following the sentence's syntax structure rather than its raw word order.

A third way to move beyond flat sequences is to treat reasoning itself as a small, composable program. Neural Module Networks is an approach for Visual Question Answering (VQA) tasks that uses a semantic parser tool to parse a natural language question and dynamically construct a deep network composed of reusable modules, such as an attention module attend[.] and a classification module classify[.].
For example, the question "What color is the cat?" may be mapped to the network layout classify[color](attend[cat]) by the semantic parser.
The constructed Neural Module Network (NMN) outputs a distribution over labels.
In addition, the model contains a separate but jointly trained LSTM that also processes the question and predicts a distribution over labels. The LSTM complements NMN by capturing the information that may get lost when the question is overly simplified by the semantic parser.
Finally, to answer the question with the associated image, the model combines the outputs of the constructed NMN and the LSTM via geometric average of their probability distributions.
The following contains a subset of reusable modules proposed in the paper :
attend[c]: turn an image into an unnormalized attention heatmap for a specific concept. For example, attend[dog] highlights the region of the image that likely contains a dog .classify[c]: takes an attention heatmap and the input image as inputs and maps them to a distribution over labels for a concept. For example, classify[color] returns a distribution over colors for the attended region.combine[c]: takes two attention heatmaps and merges them into a single attention heat map depends on the given concept. For example, combine[and] should return an attention heatmap that only highlights the regions that are active in both inputs.Learning to Reason: End-to-End Module Networks for Visual Question Answering builds on the idea in Neural Module Network (NMN) and proposes End-to-End Module Networks (N2NMNs), which learns to reason by directly predicting network layouts without relying on a semantic parser tool to parse the question first. Instead, N2NMNs use a layout policy implemented with an attentional Recurrent Neural Network to predict the network layout.
For example, the question "How many other things are there of the same size as the matte ball?" may be mapped to count(relocate(find())) by the layout policy.
Neural-Symbolic VQA (NS-VQA) has three components:

"A state machine is a computational model that consists of a collection of states, which it iteratively traverses while reading a sequence of inputs, as determined by a transition function."
Learning by Abstraction: The Neural State Machine goes a step further by converting the whole image into a probabilistic scene graph, which specifies the objects and their relations within the given image. Each node represents one of the objects (e.g. cat, apple), while each edge corresponds to the relations (e.g. behind, holding). In addition, the model translates the question into a fixed-length sequence of reasoning instructions, which are fed into the neural state machine to guide its traversal of the scene graph toward the answer.
The neural state machine starts with a uniform initial attention distribution over the states and maintains an attention distribution across object nodes. At each reasoning step, it takes a reasoning instruction derived from the question and uses it, together with the current attention distribution, to identify the most relevant neighboring state as the next step. It then updates the attention distribution over the states to shift the model’s attention from the current node to the next node. Finally, a standard fully-connected softmax classifier uses the question representation and the machine’s final state representation to predict an answer .
Hierarchical structures build domain knowledge directly into the model, and there are three types of hierarchical structures: graph structure, tree structure, and modular structure.