XenonStack
BERT Explained: Bidirectional Transformers
J
K
N
O
R
X
Y
Z

XenonStack GlossaryBERT Explained: Bidirectional Transformers

Key takeaway

  • BERT (Bidirectional Encoder Representations from Transformers) reads text in both directions. Learn how it is pre-trained, fine-tuned and used in NLP.

BERT, short for Bidirectional Encoder Representations from Transformers, is a language representation model that learns from unlabelled text by using the words to the left and to the right of every position. A single pre-trained BERT model can then be adapted to many language tasks with very little change to its architecture.

This page is for data scientists, architects and technology leaders who need a clear definition of BERT. It covers why the model mattered, how pre-training and fine-tuning work, how BERT differs from ELMo and ULMFiT, and where it fits when you build AI agents.

What is BERT and why does it matter?

The BERT paper by Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova describes a model that learns deep bidirectional representations from unlabelled text. It conditions on left and right context in all layers, rather than reading in one direction only.

That matters because the meaning of a word often depends on the words around it on both sides. The authors report that adding a single output layer to the pre-trained model was enough to reach state-of-the-art results on eleven natural language processing tasks, including question answering and language inference. It is also a form of transfer learning: the expensive learning happens once, and the result is reused.

How does BERT work?

BERT is a stack of Transformer encoders. As The Illustrated BERT explains, it uses the encoder side of the Transformer only, with no decoder stack, and each input begins with a special [CLS] token whose output can feed a classifier.

  • Masked language model: a share of the input words is hidden and the model must predict them, so it has to use context from both directions.
  • Next sentence prediction: given two sentences, the model predicts whether the second follows the first, which helps with tasks that relate sentences.
  • Fine-tuning: the pre-trained model is adapted to a task with labelled data. Mainly the added classifier is trained, with only minimal changes to BERT itself.
  • Two sizes: BERT Base has 12 encoder layers and BERT Large has 24, according to the same source.

How does BERT differ from ELMo and ULMFiT?

All three were published in 2018 and all rely on pre-training, but they reuse the pre-trained model in different ways.

Two-column diagram. Pre-training: unlabelled text, masked words, sentence pairs, encoder stack. Fine-tuning: labelled examples, output layer, minimal changes, task model.
ModelCore ideaHow it is reused
BERTTransformer encoders trained to use left and right context togetherFine-tuned with a small added output layer per task
ELMoWord vectors taken from the internal states of a deep bidirectional language modelAdded as features to an existing task model
ULMFiTA pre-trained language model fine-tuned with controlled learning ratesFine-tuned end to end for text classification

See our glossary pages on embeddings from language models and universal language model fine-tuning for each of these.

What is BERT used for?

BERT is used wherever a system must understand text rather than generate it: classifying documents, answering questions from a passage, judging whether one sentence follows from another, and tagging entities in text. Because it produces a representation of the input, it is often one component inside a larger pipeline.

How does BERT relate to AI agents?

An AI agent that reads tickets, contracts or messages needs a reliable way to interpret language before it decides what to do. Encoder models such as BERT are one way to supply that understanding. For teams building and running agents, ElixirClaw is XenonStack's AI agents computing platform.

What should you do first?

  1. Write down the language task: classification, question answering or entity tagging.
  2. Start from an openly released pre-trained BERT model rather than training from scratch.
  3. Collect a small, well-labelled set of examples for fine-tuning.
  4. Test on held-out text from your own domain before relying on the results.

To map one decision your agents make from language input, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What does BERT stand for?

BERT stands for Bidirectional Encoder Representations from Transformers. It is a language representation model that learns from unlabelled text using context on both sides of each word.

Is BERT a Transformer?

BERT is built from the encoder part of the Transformer architecture. It does not use the decoder stack.

What is the masked language model in BERT?

It is a pre-training task in which some input words are hidden and the model must predict them. This forces the model to use left and right context together.

How is BERT fine-tuned?

The pre-trained model is adapted to a specific task using labelled data. Mainly an added output layer is trained, with only minimal changes to BERT itself.

How is BERT different from ELMo?

ELMo supplies context-aware word vectors from a deep bidirectional language model that are added to an existing model. BERT is itself fine-tuned for each task.