LogoLogo
Continuum WebsiteContinuum ApplicationsContinuum KnowledgeAxolotl Platform
Continuum Knowledge
Continuum Knowledge
  • Continuum
  • Data
    • Datasets
      • Pre Training Data
      • Types of Fine Tuning
      • Self Instruct Paper
      • Self-Alignment with Instruction Backtranslation
      • Systematic Evaluation of Instruction-Tuned Large Language Models on Open Datasets
      • Instruction Tuning
      • Instruction Fine Tuning - Alpagasus
      • Less is More For Alignment
      • Enhanced Supervised Fine Tuning
      • Visualising Data using t-SNE
      • UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction
      • Training and Evaluation Datasets
      • What is perplexity?
  • MODELS
    • Foundation Models
      • The leaderboard
      • Foundation Models
      • LLama 2 - Analysis
      • Analysis of Llama 3
      • Llama 3.1 series
      • Google Gemini 1.5
      • Platypus: Quick, Cheap, and Powerful Refinement of LLMs
      • Mixtral of Experts
      • Mixture-of-Agents (MoA)
      • Phi 1.5
        • Refining the Art of AI Training: A Deep Dive into Phi 1.5's Innovative Approach
      • Phi 2.0
      • Phi-3 Technical Report
  • Training
    • The Fine Tuning Process
      • Why fine tune?
        • Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations?
        • Explanations in Fine Tuning
      • Tokenization
        • Tokenization Is More Than Compression
        • Tokenization - SentencePiece
        • Tokenization explore
        • Tokenizer Choice For LLM Training: Negligible or Crucial?
        • Getting the most out of your tokenizer for pre-training and domain adaptation
        • TokenMonster
      • Parameter Efficient Fine Tuning
        • P-Tuning
          • The Power of Scale for Parameter-Efficient Prompt Tuning
        • Prefix-Tuning: Optimizing Continuous Prompts for Generation
        • Harnessing the Power of PEFT: A Smarter Approach to Fine-tuning Pre-trained Models
        • What is Low-Rank Adaptation (LoRA) - explained by the inventor
        • Low Rank Adaptation (Lora)
        • Practical Tips for Fine-tuning LMs Using LoRA (Low-Rank Adaptation)
        • QLORA: Efficient Finetuning of Quantized LLMs
        • Bits and Bytes
        • The Magic behind Qlora
        • Practical Guide to LoRA: Tips and Tricks for Effective Model Adaptation
        • The quantization constant
        • QLORA: Efficient Finetuning of Quantized Language Models
        • QLORA and Fine-Tuning of Quantized Language Models (LMs)
        • ReLoRA: High-Rank Training Through Low-Rank Updates
        • SLoRA: Federated Parameter Efficient Fine-Tuning of Language Models
        • GaLora: Memory-Efficient LLM Training by Gradient Low-Rank Projection
      • Hyperparameters
        • Batch Size
        • Padding Tokens
        • Mixed precision training
        • FP8 Formats for Deep Learning
        • Floating Point Numbers
        • Batch Size and Model loss
        • Batch Normalisation
        • Rethinking Learning Rate Tuning in the Era of Language Models
        • Sample Packing
        • Gradient accumulation
        • A process for choosing the learning rate
        • Learning Rate Scheduler
        • Checkpoints
        • A Survey on Efficient Training of Transformers
        • Sequence Length Warmup
        • Understanding Training vs. Evaluation Data Splits
        • Cross-entropy loss
        • Weight Decay
        • Optimiser
        • Caching
      • Training Processes
        • Extending the context window
        • PyTorch Fully Sharded Data Parallel (FSDP)
        • Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
        • YaRN: Efficient Context Window Extension of Large Language Models
        • Sliding Window Attention
        • LongRoPE
        • Reinforcement Learning
        • An introduction to reinforcement learning
        • Reinforcement Learning from Human Feedback (RLHF)
        • Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  • INFERENCE
    • Why is inference important?
      • Grouped Query Attention
      • Key Value Cache
      • Flash Attention
      • Flash Attention 2
      • StreamingLLM
      • Paged Attention and vLLM
      • TensorRT-LLM
      • Torchscript
      • NVIDIA L40S GPU
      • Triton Inference Server - Introduction
      • Triton Inference Server
      • FiDO: Fusion-in-Decoder optimised for stronger performance and faster inference
      • Is PUE a useful measure of data centre performance?
      • SLORA
  • KNOWLEDGE
    • Vector Databases
      • A Comprehensive Survey on Vector Databases
      • Vector database management systems: Fundamental concepts, use-cases, and current challenges
      • Using the Output Embedding to Improve Language Models
      • Decoding Sentence-BERT
      • ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERT
      • SimCSE: Simple Contrastive Learning of Sentence Embeddings
      • Questions Are All You Need to Train a Dense Passage Retriever
      • Improving Text Embeddings with Large Language Models
      • Massive Text Embedding Benchmark
      • RocketQAv2: A Joint Training Method for Dense Passage Retrieval and Passage Re-ranking
      • LLM2Vec: Large Language Models Are Secretly Powerful Text Encoders
      • Embedding and Fine-Tuning in Neural Language Models
      • Embedding Model Construction
      • Demystifying Embedding Spaces using Large Language Models
      • Fine-Tuning Llama for Multi-Stage Text Retrieval
      • Large Language Model Based Text Augmentation Enhanced Personality Detection Model
      • One Embedder, Any Task: Instruction-Finetuned Text Embeddings
      • Vector Databases are not the only solution
      • Knowledge Graphs
        • Harnessing Knowledge Graphs to Elevate AI: A Technical Exploration
        • Unifying Large Language Models and Knowledge Graphs: A Roadmap
      • Approximate Nearest Neighbor (ANN)
      • High Dimensional Data
      • Principal Component Analysis (PCA)
      • Vector Similarity Search - HNSW
      • FAISS (Facebook AI Similarity Search)
      • Unsupervised Dense Retrievers
    • Retrieval Augmented Generation
      • Retrieval-Augmented Generation for Large Language Models: A Survey
      • Fine-Tuning or Retrieval?
      • Revolutionising Information Retrieval: The Power of RAG in Language Models
      • A Survey on Retrieval-Augmented Text Generation
      • REALM: Retrieval-Augmented Language Model Pre-Training
      • Retrieve Anything To Augment Large Language Models
      • Generate Rather Than Retrieve: Large Language Models Are Strong Context Generators
      • Active Retrieval Augmented Generation
      • DSPy: LM Assertions: Enhancing Language Model Pipelines with Computational Constraints
      • DSPy: Compiling Declarative Language Model Calls
      • DSPy: In-Context Learning for Extreme Multi-Label Classification
      • Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs
      • HYDE: Revolutionising Search with Hypothetical Document Embeddings
      • Enhancing Recommender Systems with Large Language Model Reasoning Graphs
      • Retrieval Augmented Generation (RAG) versus fine tuning
      • RAFT: Adapting Language Model to Domain Specific RAG
      • Summarisation Methods and RAG
      • Lessons Learned on LLM RAG Solutions
      • Stanford: Retrieval Augmented Language Models
      • Overview of RAG Approaches with Vector Databases
      • Mastering Chunking in Retrieval-Augmented Generation (RAG) Systems
    • Semantic Routing
    • Resource Description Framework (RDF)
  • AGENTS
    • What is agency?
      • Rephrase and Respond: Let Large Language Models Ask Better Questions for Themselves
      • Types of Agents
      • The risk of AI agency
      • Understanding Personality in Large Language Models: A New Frontier in AI Psychology
      • AI Agents - Reasoning, Planning, and Tool Calling
      • Personality and Brand
      • Agent Interaction via APIs
      • Bridging Minds and Machines: The Legacy of Newell, Shaw, and Simon
      • A Survey on Language Model based Autonomous Agents
      • Large Language Models as Agents
      • AI Reasoning: A Deep Dive into Chain-of-Thought Prompting
      • Enhancing AI Reasoning with Self-Taught Reasoner (STaR)
      • Exploring the Frontier of AI: The "Tree of Thoughts" Framework
      • Toolformer: Revolutionising Language Models with API Integration - An Analysis
      • TaskMatrix.AI: Bridging Foundational AI Models with Specialised Systems for Enhanced Task Completion
      • Unleashing the Power of LLMs in API Integration: The Rise of Gorilla
      • Andrew Ng's presentation on AI agents
      • Making AI accessible with Andrej Karpathy and Stephanie Zhan
  • Regulation and Ethics
    • Regulation and Ethics
      • Privacy
      • Detecting AI Generated content
      • Navigating the IP Maze in AI: The Convergence of Blockchain, Web 3.0, and LLMs
      • Adverse Reactions to generative AI
      • Navigating the Ethical Minefield: The Challenge of Security in Large Language Models
      • Navigating the Uncharted Waters: The Risks of Autonomous AI in Military Decision-Making
  • DISRUPTION
    • Data Architecture
      • What is a data pipeline?
      • What is Reverse ETL?
      • Unstructured Data and Generatve AI
      • Resource Description Framework (RDF)
      • Integrating generative AI with the Semantic Web
    • Search
      • BM25 - Search Engine Ranking Function
      • BERT as a reranking engine
      • BERT and Google
      • Generative Engine Optimisation (GEO)
      • Billion-scale similarity search with GPUs
      • FOLLOWIR: Evaluating and Teaching Information Retrieval Models to Follow Instructions
      • Neural Collaborative Filtering
      • Federated Neural Collaborative Filtering
      • Latent Space versus Embedding Space
      • Improving Text Embeddings with Large Language Models
    • Recommendation Engines
      • On Interpretation and Measurement of Soft Attributes for Recommendation
      • A Survey on Large Language Models for Recommendation
      • Model driven recommendation systems
      • Recommender AI Agent: Integrating Large Language Models for Interactive Recommendations
      • Foundation Models for Recommender Systems
      • Exploring the Impact of Large Language Models on Recommender Systems: An Extensive Review
      • AI driven recommendations - harming autonomy?
    • Logging
      • A Taxonomy of Anomalies in Log Data
      • Deeplog
      • LogBERT: Log Anomaly Detection via BERT
      • Experience Report: Deep Learning-based System Log Analysis for Anomaly Detection
      • Log-based Anomaly Detection with Deep Learning: How Far Are We?
      • Deep Learning for Anomaly Detection in Log Data: A Survey
      • LogGPT
      • Adaptive Semantic Gate Networks (ASGNet) for log-based anomaly diagnosis
  • Infrastructure
    • The modern data centre
      • Enhancing Data Centre Efficiency: Strategies to Improve PUE
      • TCO of NVIDIA GPUs and falling barriers to entry
      • Maximising GPU Utilisation with Kubernetes and NVIDIA GPU Operator
      • Data Centres
      • Liquid Cooling
    • Servers and Chips
      • The NVIDIA H100 GPU
      • NVIDIA H100 NVL
      • Lambda Hyperplane 8-H100
      • NVIDIA DGX Servers
      • NVIDIA DGX-2
      • NVIDIA DGX H-100 System
      • NVLink Switch
      • Tensor Cores
      • NVIDIA Grace Hopper Superchip
      • NVIDIA Grace CPU Superchip
      • NVIDIA GB200 NVL72
      • Hopper versus Blackwell
      • HGX: High-Performance GPU Platforms
      • ARM Chips
      • ARM versus x86
      • RISC versus CISC
      • Introduction to RISC-V
    • Networking and Connectivity
      • Infiniband versus Ethernet
      • NVIDIA Quantum InfiniBand
      • PCIe (Peripheral Component Interconnect Express)
      • NVIDIA ConnectX InfiniBand adapters
      • NVMe (Non-Volatile Memory Express)
      • NVMe over Fabrics (NVMe-oF)
      • NVIDIA Spectrum-X
      • NVIDIA GPUDirect
      • Evaluating Modern GPU Interconnect
      • Scalable Hierarchical Aggregation and Reduction Protocol (SHARP)
      • Next-generation networking in AI environments
      • NVIDIA Collective Communications Library (NCCL)
    • Data and Memory
      • NVIDIA BlueField Data Processing Units (DPUs)
      • Remote Direct Memory Access (RDMA)
      • High Bandwidth Memory (HBM3)
      • Flash Memory
      • Model Requirements
      • Calculating GPU memory for serving LLMs
      • Transformer training costs
      • GPU Performance Optimisation
    • Libraries and Complements
      • NVIDIA Base Command
      • NVIDIA AI Enterprise
      • CUDA - NVIDIA GTC 2024 presentation
      • RAPIDs
      • RAFT
    • Vast Data Platform
      • Vast Datastore
      • Vast Database
      • Vast Data Engine
      • DASE (Disaggregated and Shared Everything)
      • Dremio and VAST Data
    • Storage
      • WEKA: A High-Performance Storage Solution for AI Workloads
      • Introduction to NVIDIA GPUDirect Storage (GDS)
        • GDS cuFile API
      • NVIDIA Magnum IO GPUDirect Storage (GDS)
      • Vectors in Memory
Powered by GitBook
LogoLogo

Continuum - Accelerated Artificial Intelligence

  • Continuum Website
  • Axolotl Platform

Copyright Continuum Labs - 2023

On this page
  • Model Architecture
  • Pretraining
  • Masked Language Model (MLM)
  • Example:
  • Next Sentence Prediction (NSP)
  • Example:
  • Input Representation
  • Fine-tuning
  • Experimental Results
  • Conclusion and Impact of BERT

Was this helpful?

  1. DISRUPTION
  2. Search

BERT and Google

PreviousBERT as a reranking engineNextGenerative Engine Optimisation (GEO)

Last updated 11 months ago

Was this helpful?

BERT (Bidirectional Encoder Representations from Transformers) was a groundbreaking language representation model that revolutionised the field of natural language processing (NLP) when it was introduced in 2018.

The key innovation of BERT was its ability to learn contextual representations of words by jointly conditioning on both the left and right context in all layers of the model.

This bidirectional nature allowed BERT to capture rich semantic information and understand the complex relationships between words in a sentence.

Unlike previous models that only analysed text in one direction, BERT processed words in relation to all other words in a sentence, allowing for a deep, bidirectional understanding of context.

BERT was integrated into Google Search in 2019 to enhance its understanding of the nuances and context of user queries, significantly improving the quality of search results.

Prior to BERT, Google Search mainly relied on keyword matching to retrieve relevant results.

BERT's deep bidirectional understanding allowed Google to grasp the intent behind queries more effectively, especially for longer, more conversational phrases or when the query uses prepositions like "for" and "to," which can alter the meaning.

Model Architecture

BERT uses a multi-layer bidirectional Transformer encoder as its base architecture.

The input representation is constructed by summing the token embeddings, segment embeddings, and position embeddings.

The token embeddings are the learned representations of each token, the segment embeddings distinguish between sentence pairs, and the position embeddings capture the relative position of each token.

Pretraining

BERT is pre-trained on a large corpus of unlabelled text using two unsupervised tasks: Masked Language Modeling (MLM) and Next Sentence Prediction (NSP).

Masked Language Model (MLM)

The MLM task is designed to enable bidirectional representation learning in BERT.

The main idea is to randomly mask some percentage of the input tokens and then predict those masked tokens based on the context provided by the unmasked tokens.

This allows the model to learn from both the left and right context of a masked token.

Here's how the MLM task works:

  1. Randomly select 15% of the tokens in the input sequence.

  2. For each selected token, perform the following:

    • 80% of the time: Replace the token with the special [MASK] token.

    • 10% of the time: Replace the token with a random token from the vocabulary.

    • 10% of the time: Keep the token unchanged.

  3. Feed the modified sequence into the BERT model.

  4. Predict the original token for each masked position using the final hidden vectors corresponding to the masked tokens.

  5. Calculate the cross-entropy loss between the predicted tokens and the original tokens.

Example:

Original sentence: "The quick brown fox jumps over the lazy dog."

Masked sentence: "The quick [MASK] fox [MASK] over the lazy [MASK]."

In this example, the words "brown," "jumps," and "dog" are masked. The model then predicts the original words based on the context provided by the unmasked tokens.

By masking tokens randomly, BERT learns to predict words based on both the left and right context, allowing it to learn bidirectional representations.

Next Sentence Prediction (NSP)

The NSP task is designed to capture the relationship between two sentences, which is important for downstream tasks like Question Answering (QA) and Natural Language Inference (NLI).

The goal is to predict whether the second sentence follows the first sentence in the original text.

Here's how the NSP task works:

  1. For each pre-training example, choose two sentences (A and B) from the corpus.

  2. 50% of the time, B is the actual next sentence that follows A (labeled as IsNext).

  3. 50% of the time, B is a random sentence from the corpus (labeled as NotNext).

  4. Feed the sentence pair (A and B) into the BERT model, separated by the special [SEP] token.

  5. Use the final hidden vector corresponding to the [CLS] token (C in Figure 1 of the paper) for binary classification (IsNext or NotNext).

Example:

Sentence A: "The quick brown fox jumps over the lazy dog."

Sentence B (IsNext): "The dog was not amused by the fox's antics."

Sentence B (NotNext): "Penguins are flightless birds found in the Southern Hemisphere."

In this example, the sentence pair (A, B) with "IsNext" label represents a coherent sequence, while the sentence pair (A, B) with "NotNext" label is not coherent.

By training on the Next Sentence Prediction task, BERT learns to understand the relationship between sentences.

During pre-training, BERT is trained on a large corpus (e.g., BooksCorpus and Wikipedia) using these two tasks.

The model learns to capture the contextual representations of words by attending to both the left and right context in all layers.

Input Representation

To perform these tasks, BERT takes an input sequence of tokens and constructs an input representation by summing the token embeddings, segment embeddings, and position embeddings.

As per the diagram below:

Token embeddings: Learned embeddings for each token in the input sequence.

Segment embeddings: Embeddings indicating which sentence each token belongs to (sentence A or B).

Position embeddings: Embeddings representing the relative position of each token in the sequence.

This input representation allows BERT to capture both the token-level information and the sentence-level structure during pre-training.

Fine-tuning

After pre-training, BERT can be fine-tuned on specific downstream tasks with minimal task-specific architecture changes.

Input Representation

  • The input sequence is tokenized and converted into input embeddings.

  • The input embeddings are the sum of token embeddings, segment embeddings (to differentiate sentences), and position embeddings (to capture positional information).

Task-Specific Output Layer

  • For each downstream task, a task-specific output layer is added on top of the pre-trained BERT model.

  • For sequence-level classification tasks (e.g., sentiment analysis), the output layer is typically a simple classifier that takes the representation of the [CLS] token (the first token of the sequence) as input.

  • For token-level tasks (e.g., named entity recognition), the output layer is applied to each token's representation to make predictions.

Fine-tuning Procedure

  • The pre-trained BERT model is initialised with the pre-trained weights.

  • The task-specific output layers are added on top of the pre-trained model.

  • The entire model (pre-trained BERT + task-specific layers) is fine-tuned on the labeled data for the downstream task.

  • The model is trained using standard supervised learning techniques, such as cross-entropy loss for classification tasks.

  • The fine-tuning process typically involves a smaller learning rate and fewer training epochs compared to pre-training.

By leveraging the pre-trained representations learned during the unsupervised pre-training phase, BERT can achieve state-of-the-art performance on a wide range of downstream tasks with minimal task-specific architecture changes and fine-tuning.

The fine-tuning approach allows BERT to adapt its general language understanding capabilities to specific tasks, making it a powerful and versatile model for various natural language processing applications.

Experimental Results

The authors evaluate BERT on a wide range of natural language processing tasks, including sentence-level tasks (e.g., natural language inference, paraphrasing) and token-level tasks (e.g., named entity recognition, question answering).

BERT achieves state-of-the-art results on eleven tasks, demonstrating its effectiveness as a pre-training approach.

Conclusion and Impact of BERT

BERT (Bidirectional Encoder Representations from Transformers) represented a significant breakthrough in the field of natural language processing (NLP).

The fundamental innovation of BERT was in its ability to pre-train deep bidirectional representations from unlabelled text by jointly conditioning on both left and right context in all layers.

The bidirectional nature of BERT allows it to capture rich contextual information from both directions, making it particularly well-suited for understanding the complex relationships between words and sentences.

This is important for tasks such as question answering, where the model needs to consider the entire context to provide accurate answers.

Another key innovation of BERT is the use of the Transformer architecture, which enables efficient parallel training and captures long-range dependencies in text.

The Transformer's self-attention mechanism allows each word to attend to all other words in the input sequence, enabling the model to learn more expressive and nuanced representations.

The impact of BERT has been significant in both academia and industry.

In real-world applications, BERT has been widely adopted by companies and organisations to improve their NLP systems.

For example, Google has used BERT to enhance its search engine results, Microsoft has integrated BERT into its Bing search engine and Office products, and many chatbot and virtual assistant platforms have leveraged BERT to improve their conversational capabilities.

Moreover, BERT has inspired numerous variants and extensions, such as RoBERTa, ALBERT, and DistilBERT, which aim to improve upon the original model in terms of performance, efficiency, and scalability.

The success of BERT has also paved the way for more advanced language models, which have pushed the boundaries of what is possible with NLP.

LogoBERT: Pre-training of Deep Bidirectional Transformers for Language...arXiv.org
BERT - the seminal paper cited nearly 100,000 times
BERT input representation. The input embeddings are the sum of the token embeddings, the segmentation embeddings and the position embeddings
Overall pre-training and fine-tuning procedures for BERT. Apart from output layers, the same architectures are used in both pre-training and fine-tuning. The same pre-trained model parameters are used to initialise models for different down-stream tasks. During fine-tuning, all parameters are fine-tuned. [CLS] is a special symbol added in front of every input example, and [SEP] is a special separator token (e.g. separating questions/answer
Page cover image