A collection of fragments of understanding in the pursuit of deeper questions.
Content of the Lecture
Selective Sensory Attention in Cognitive Neuroscience "It is the taking possession by the mind in clear and vivid form, of one out of what seem several simultaneously possible objects or trains of thought ... It implies withdrawal from some things in order to deal effectively with other,..." - William James in Principles of Psychology (1890)
"Attention is the flexible control of limited computational resources" - Lindsay (2020)
Function of Selective Attention
Bottom-Up Attention Something immediately draws our eye to the Toblerone and the Matterhorn. This something is visual saliency.
Visual Saliency
Nowadays DL is exploited to predict saliency spots in pictures. They take ground truth data and train neural networks to predict saliency points in images with higher accuracy than older models. Such models are also exploited to work in the other direction and help in designing images to convey attention towards specific points of the figure.
Top-Down Attention
Selective Top-Down Attention Neural Signals have been measured in Primates. The primates watch a screen and fix the white dot. Then the three stimuli went on and the cue went on (the central dot that changes color). The researchers used electrophysiology to record the activity of individual neurons in the visual cortex of monkeys as they performed a visual search task. The goal of the task was to detect a target stimulus among a set of distractors. The researches found that attentional modulation was present in both feedforward and feedback signals in the visual cortex, with top-down attentional signals strengthening target-selective responses and suppressing responses to distractors. This study provides evidence for the role of top-down attentional signals in modulating both feedforward and feedback processing in the primate visual cortex, and suggests a mechanism by which attention can selectively enhance target representation and improve perceptual processing.
The paper "Selective Top-Down Attention Modulates Feedforward and Feedback Neural Signals in Primates" by Paperi et al. (2017) investigated the effect of top-down attention on feedforward and feedback signals in primate brains. The study found that when attention was directed towards a particular visual stimulus, both feedforward and feedback signals increased in the regions of the brain responsible for processing that stimulus, demonstrating that top-down attention can modulate both feedforward and feedback signals. These results suggest that attention plays a crucial role in shaping neural processing in the visual system, and that top-down attention can dynamically influence feedforward and feedback signals to enhance processing of behaviorally relevant information.
Attention in Deep Learning In the field of Machine Learning, attention is a mechanism used by certain types of neural networks to selectively focus on certain parts of an input when processing it. This is useful because it allows the model to automatically learn to focus on the most relevant parts of the input, which can improve its performance on a given task. For example, an attention mechanism might be used in a machine translation model to automatically focus on the words in the source sentence that are most relevant for generating the correct translation.
We'll focus here on time-series attention models.
![]() |
![]() |
|---|
This is a sequence-to-sequence neural network. You want your architecture to produce an output for every timestamp. And usually you do these through RNNs (LSTMs), which features hidden states and recalls previous states of the network, thus requires a sequential step-by-step calculation of the states. On the other hand we have CNNs which are great in parallelization, but the downside is their finite and fixed memory (loose flexibility). Can we combine these two architectures? That is, can we have the long dependencies and flexibility of RNNs together with the parallelization properties of CNNs? Here is where Self-Attention (SA) Models come in.
The outputs are calculate according to the formula in the right figure, however the key peculiarity is that W is not a parameter of the model that is learnt through gradient descent. It is a parameter that indicates how similar the inputs are similar between them and are calculated as shown in the following figure. These weights are passed through a Softmax such that the sum of all weights add up to 1.
![]() |
![]() |
|---|
![]() |
![]() |
|---|
Intuition how Self-Attention works: The Dot Product Let's say we want to try a model to understand the sentiment of some restaurant reviews (like in the example below). The word "terrible" is something that probably we wouldn't like to have in a restaurant review, however if it comes after "not too" is probably not such a bad review. Hence, our model should pose attention also to these part of the sentence to understand the overall sentiment of the phrase, i.e., the weight between "not" and "terrible" should be a major one in our self-attention matrix. Which implies that the model should be capable of understanding the dependencies between the input "not" and "terrible" and how it modulates the meaning.
![]() |
![]() |
|---|
Improving Self-Attention
![]() |
![]() |
|---|
![]() |
![]() |
|---|
Recap of Self-Attention Self-Attention: Sequence-To-Sequence layer with Parallel Computation and Perfect Long-Term Memory. Fundamentally a set-to-set layer, no access to the sequential structure of the input. A large part of the behavior comes from the parameters upstream.
Transformers Any sequence-based model that primarily uses self-attention to propagate information along the time dimension. More broadly: any model that primarily uses self-attention to propagate information between the basic units of our instances.
The transformer architecture is based on blocks as the one showed below that are stucked on each other as shown in the right figure.
![]() |
![]() |
|---|
The Auto-Regressive Transformer One problem that we still have is making sure that the network cannot access information regarding upcoming targets from the previous layers. In order to do this we calculate the Causal Self-Attention weight matrix and all future values are set to minus infinity.
Causal Self-Attention By using Causal Self-Attention we force the network to figure out which words are important in the previous sequence to generate the following letter or word. The blocks that feature such characteristic are named Causal Transformer Blocks.
The Causal Autoregressive Transformer
![]() |
![]() |
|---|
The Transformer: Position Embeddings The last problem we have to address is "repetition of words" or again different meanings associated with the same word (e.g., "The"). In order to overcome this limitation, Position Embeddings are used, so that same words are considered differently by the network.
The "Original Transformer" (ELMo) Adding all these features together, we obtain the very first transformer ELMo from the paper "Attention Is All You Need" that was exploited for language translation. It was a machine translation model with no recurrent layers or convolutions, but rather an encoder/decoder configuration with positional encoding. It featured 512 dims, 8 heads, 2x6 blocks. It has been trained for 3.5 days on 8 GPUs.
The GPT3 Transformer Autoregressive language model. Single stack of causal trf blocks with positional embeddings. 12288 dims, 96 heads, 96 blocks, sequence size 2048 and 175 billion total parameters. It has been trained on 10000 GPUs, likely in around 12 days for about $4,6 million.
Training Transformer Models
Jeopardy Questions