Adaptive Masking

Adaptive Masking is a type of attention mechanism used in machine learning that allows a model to learn its own context size to attend over. This is done by adding a masking function for each head in Multi-Head Attention to control for the span of the attention.

What is a Masking Function?

A masking function is a non-increasing function that maps a distance to a value in [0, 1]. This function is added to the attention mechanism to pay more attention to important information and ignore the irrelevant information. The adaptive masking technique uses a soft masking function, which is a piecewise function inspired by a study conducted by Jernite et al. in 2017.

How Does Adaptive Masking Work?

Adaptive masking uses a soft masking function, which is parametrized by a real value z in [0, S]. The value of S is the context size that the model is trained to learn. The shape of the soft masking function is influenced by a hyper-parameter R that determines its softness.

The attention weights from the masked span are then computed using the following formula:

atr = mz(t-r) exp(str) / Σq=t-St-1 mz(t-q) exp(stq)

Here, mz is the soft masking function parametrized by z, and s is the input sequence.

Regularization with Adaptive Masking

Regularization is a technique used in machine learning to reduce the effect of overfitting, which occurs when the model performs well on the training data but poorly on the testing data. In Adaptive Masking, regularization is achieved using a L1 penalization added on the parameters zi for each attention head i of the model to the loss function.

The formula for the loss function is:

L = - log P(w1, ..., wT) + λ/M Σi zi

Here, P is the probability of the output sequence, w is the input sequence, and λ is the regularization hyperparameter. M is the number of heads in each layer. This formulation is differentiable in the parameters zi, which means they are learnt jointly with the rest of the model.

Adaptive Masking is a powerful attention mechanism in machine learning that allows the model to learn its own context size for attend over. By using a soft masking function and regularization techniques, Adaptive Masking reduces the effect of overfitting and improves the performance of the model. This technique is widely used in natural language processing, computer vision, and other areas where attention mechanisms are required to handle large amounts of data.

Great! Next, complete checkout for full access to SERP AI.
Welcome back! You've successfully signed in.
You've successfully subscribed to SERP AI.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.