Skip to content
StackDecode
AI & ML Atlas
Deep LearningarchitectureInteractive simulation

BERT

A bidirectional transformer encoder pre-trained by filling in masked words.

The idea

BERT hides about 15% of the tokens in a sentence and learns to predict them from the surrounding words on both sides, so each token's representation uses full context. The pre-trained model is then fine-tuned with a small head for tasks such as classification or question answering.

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

thecatsatonthemat
  • positive
  • negative
  • attention weight

Take the sentence. We will compute what the word "cat" (highlighted) should pay attention to.

1/4

The vectors here are random, so the pattern of attention is arbitrary. In a trained model these weights are learned. Pick another query word with the slider.

Step by step

  1. 1Mask some tokens in a large amount of text.
  2. 2Run the transformer encoder with full bidirectional attention.
  3. 3Predict the masked tokens (masked language modelling).
  4. 4Fine-tune on a downstream task with labelled data.

Where it is used

Search ranking, classification, entity recognition, question answering.

Watch out for

An encoder: it does not generate text naturally.

Related