How to talk our customers off the ledge…
Tim Sent · Director, Enterprise Architecture — Tech, Media & Telecom · June 24, 2024
A case for Retrieval-Augmented Generation over training a proprietary LLM from scratch — the cost curve behind frontier models, the history of deep learning and transformers that got us here, the datasets and benchmarks the field trains and evaluates against, the word-embedding and attention mechanics underneath every modern model, and the RAG and vector-database architecture that makes pre-trained models enterprise-ready without a nine-figure training bill.
Overview
Motivation for proprietary LLMs, business demands fueling model growth, and the true costs of training frontier models.
Word embeddings, deep learning foundations, and the attention mechanism that produced the transformer era.
Open-source training datasets and the benchmarks used to evaluate language model performance.
Retrieval-Augmented Generation as the practical alternative to training from scratch.
Hypothesis
Retrieval-Augmented Generation (RAG) achieves better results than training a proprietary large language model due to lower initial costs, reduced maintenance requirements, access to diverse data sources, optimized utilization of human resources, and the integration of extensive pre-existing knowledge.
Deep Learning Foundations
1943
The Perceptron
Invented by Warren McCulloch and Walter Pitts.
1958
Rosenblatt's Perceptron
Frank Rosenblatt introduces the Perceptron, an early form of neural network, demonstrating the potential of machines to learn from data.
1965
First Deep Feedforward Network
Published by Alexey Grigorevich Ivakhnenko and Valentin Lapa.
1975
Backpropagation
Paul Werbos introduces the concept of backpropagation in his PhD thesis, though it does not gain immediate recognition.
1982
Hopfield Network
John Hopfield introduces a neural network architecture capable of serving as an associative memory system.
1986
Backpropagation Popularized
David Rumelhart, Geoffrey Hinton, and Ronald Williams popularize backpropagation, allowing multi-layer networks to learn complex patterns — the beginning of the modern era of neural networks.
1990
Elman Network
A form of recurrent neural network (RNN) capable of processing sequences by maintaining a state that captures temporal information.
1997
LSTM
Long Short-Term Memory networks are introduced by Sepp Hochreiter and Jürgen Schmidhuber, addressing the vanishing-gradient problem in traditional RNNs and enabling long-range dependency learning.
2006
Deep Belief Networks
Geoffrey Hinton and colleagues introduce Deep Belief Networks, sparking renewed interest in deep learning with efficient training methods for deep architectures.
2009
Dropout
Introduced by Geoffrey Hinton as a technique for preventing overfitting, improving the generalization of deep networks.
2012
AlexNet
Alex Krizhevsky, Ilya Sutskever, and Geoffrey Hinton win the ImageNet competition by a large margin, significantly pushing forward deep learning in computer vision.
2014
GANs & Seq2Seq
Ian Goodfellow et al. introduce Generative Adversarial Networks. The same year, Google's Seq2Seq models revolutionize sequence learning, using two RNNs to transform an input sequence into an output sequence — useful for tasks like machine translation.
Attention Mechanism & Transformers
2017
"Attention Is All You Need"
Vaswani et al. introduce the original Transformer model, replacing recurrent layers with self-attention — enabling significantly more parallelization and improving training speed and performance on tasks like translation.
2018
BERT & GPT
Google releases BERT, pre-training deep bidirectional representations to state-of-the-art results across NLP benchmarks. OpenAI introduces GPT, a 117M-parameter transformer pre-trained on a large text corpus, showing a pre-trained transformer can generate coherent, contextually relevant text.
2019
GPT-2 & DistilBERT
OpenAI scales to GPT-2 (1.5B parameters), showing greater ability to generate coherent, persuasive text. DistilBERT introduces knowledge distillation — 40% smaller, 60% faster, most of BERT's performance retained.
2020
GPT-3
OpenAI releases GPT-3 at 175 billion parameters, demonstrating strong performance across tasks without task-specific tuning — setting a new standard for generative models.
2021
Data2Vec & Switch Transformers
Facebook's Data2Vec learns representations across text, images, and sound via self-supervised learning. Google's Switch Transformers use a mixture-of-experts approach, training very large models more efficiently by routing tokens to different parameter subsets.
2022
PaLM & InstructGPT
Google's PaLM demonstrates pathway-based model scaling with state-of-the-art multitasking and generalization results. OpenAI's InstructGPT trains models to follow instructions better, paving the way for practical applications.
2023
GPT-4 & LLaMA
OpenAI introduces GPT-4, refining the balance between generative capability and controlled output. Meta releases LLaMA (7B–65B parameters), then LLaMA-2 (7B/13B/70B), then LLaMA-3 (8B/70B, pre-trained on ~15T tokens) — each aiming for a more accessible alternative to closed models.
Customer Motivations
Companies are motivated to create proprietary large language models to achieve tailored solutions that meet specific business needs, enhance competitive differentiation, maintain control over data privacy and security, and drive innovation aligned with their strategic objectives.
Case Study
BloombergGPT is a specialized transformer-based language model designed by Bloomberg to enhance NLP capabilities within the financial domain. It incorporates a large number of layers and attention heads, tailored to process and analyze vast amounts of financial data. It excels at financial sentiment analysis, named entity recognition, and market prediction.
Trained on "news, filings, press releases, web-scraped financial documents, and social media drawn from Bloomberg archives."
arxiv.org/abs/2303.17564 — Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin
Landscape
Full accessibility of source code and model weights. Community-driven development, modifiable, complete transparency in training data and methods, cost-effective.
Exclusive access requiring payment or agreements. High performance, comprehensive support, frequent updates, security and compliance measures.
Limited public accessibility, often through specific platforms or usage limits. Research-focused, benefits from community contributions, generally more transparent than proprietary models.
Costs of Training Large Language Models
The Rising Costs of Frontier AI Models
The costs of training frontier AI models have grown dramatically, but there is limited public data on the magnitude and growth of these expenses. Epoch AI's analysis estimates training costs using three approaches accounting for hardware, energy, cloud rental, and staff expenses.
Cost to train the most compute-intensive models has grown 2.4× per year since 2016 (95% CI: 2.0×–3.1×)
For frontier models like GPT-4 and Gemini, the largest expenses are AI accelerator chips and staff costs — each tens of millions of dollars
Other notable costs: server components (15–22%), cluster-level interconnect (9–13%), and energy consumption (2–6%)
arxiv.org/abs/2405.21015 — Ben Cottier, Robi Rahman, Loredana Fattorini, Nestor Maslej, David Owen
Scale
Parameter counts of major public and proprietary models, October 2018 (BERT) through May 2024 (GPT-4o) — plotted on a log scale.
Selected models plotted from the table below (log-scale parameter count vs. release date). Red points mark OpenAI's GPT-3 → GPT-4 jump — roughly a 10× parameter increase in under three years.
| Model | Parameters | Developer | Release Date | Corpus Size | Ctx Window | Type |
|---|---|---|---|---|---|---|
| Gemma | 7,000,000,000,000 | February 2024 | 6T Tokens | 8,192 | Decoder-Only | |
| Phi-2 | 2,700,000,000,000 | Microsoft | December 2023 | 1.4T Tokens | 2,048 | Decoder-Only |
| Claude 3 Opus | 2,000,000,000,000 | Anthropic | March 2024 | — | 200,000 | Encoder-Decoder |
| GPT-4o | 1,760,000,000,000 | OpenAI | May 2024 | — | 128,000 | Decoder-Only |
| GPT-4 Turbo | 1,760,000,000,000 | OpenAI | November 2023 | — | 128,000 | Decoder-Only |
| GPT-4 | 1,760,000,000,000 | OpenAI | March 2023 | — | 8,192 | Decoder-Only |
| GPT-3 | 175,000,000,000 | OpenAI | June 2020 | 3000B Tokens | 16,385 | Decoder-Only |
| LLaMA 3 | 70,000,000,000 | Meta AI | April 2024 | 15T Tokens | 8,192 | Decoder-Only |
| Claude 3 Sonnet | 70,000,000,000 | Anthropic | March 2024 | — | 200,000 | Encoder-Decoder |
| Bloomberg GPT | 50,000,000,000 | Bloomberg | March 2023 | 700B Tokens | — | Decoder-Only |
| Mixtral 8x7B | 46,700,000,000 | Mixtral | January 2024 | — | 64,000 | Decoder-Only |
| Claude 3 Haiku | 20,000,000,000 | Anthropic | March 2024 | — | 200,000 | Encoder-Decoder |
| T5 11B | 11,000,000,000 | Google AI | October 2019 | 34B Tokens | 512 | Encoder-Decoder |
| Mistral 7B | 7,300,000,000 | Mixtral | September 2023 | — | 32,000 | Decoder-Only |
| GPT-J | 6,000,000,000 | EleutherAI | June 2021 | — | 2,048 | Decoder-Only |
| T5 3B | 3,000,000,000 | Google AI | October 2019 | — | 512 | Encoder-Decoder |
| GPT-Neo 2.7B | 2,700,000,000 | EleutherAI | March 2021 | — | 2,048 | Decoder-Only |
| CTRL | 1,600,000,000 | Salesforce | September 2019 | — | 256 | Decoder-Only |
| GPT-2 (largest) | 1,500,000,000 | OpenAI | February 2019 | — | 1,024 | Decoder-Only |
| GPT-Neo 1.3B | 1,300,000,000 | EleutherAI | March 2021 | — | 2,048 | Decoder-Only |
| T5 Large | 770,000,000 | Google AI | October 2019 | — | 512 | Encoder-Decoder |
| XLM-R Large | 550,000,000 | Facebook AI | November 2019 | — | 512 | Encoder-Only |
| BART Large | 406,000,000 | Meta AI | October 2019 | — | 1,024 | Encoder-Decoder |
| RoBERTa Large | 355,000,000 | Meta AI | July 2019 | — | 512 | Encoder-Only |
| BERT Large | 340,000,000 | Google AI | October 2018 | — | 512 | Encoder-Only |
| ERNIE 2.0 Large | 340,000,000 | Baidu | July 2019 | — | 512 | Encoder-Only |
| ELECTRA Large | 335,000,000 | Google AI | March 2020 | — | 512 | Encoder-Only |
| Marian MT | 300,000,000 | Microsoft | October 2020 | — | 512 | Encoder-Decoder |
| XLM-R Base | 270,000,000 | Meta AI | November 2019 | — | 512 | Encoder-Only |
| T5 Base | 220,000,000 | Google AI | October 2019 | — | 512 | Encoder-Decoder |
| RoBERTa Base | 125,000,000 | Meta AI | July 2019 | — | 512 | Encoder-Only |
| BERT Base | 110,000,000 | Google AI | October 2018 | — | 512 | Encoder-Only |
| XLNet Base | 110,000,000 | Google AI | June 2019 | — | 512 | Encoder-Only |
| ERNIE 2.0 Base | 110,000,000 | Baidu | July 2019 | — | 512 | Encoder-Only |
| DistilBERT | 66,000,000 | Hugging Face | October 2019 | — | 512 | Encoder-Only |
| T5 Small | 60,000,000 | Google AI | October 2019 | — | 512 | Encoder-Decoder |
A frontier model is a state-of-the-art machine learning model representing the pinnacle of current capabilities — typically characterized by massive parameter counts, enabling it to process and understand vast amounts of data.
Chinchilla
Chinchilla is a family of large language models developed by DeepMind and introduced in March 2022, named as a successor to the Gopher model family, designed to further explore the scaling laws of large language models.
Researchers trained models ranging from 70 million to over 16 billion parameters on 5 to 500 billion tokens, and found that models trained following the optimal scaling law significantly outperformed larger, undertrained models such as GPT-3 and Megatron-Turing NLG.
| Model | Layers | Heads | Key/Value Size | Dimension |
|---|---|---|---|---|
| Gopher 280B | 80 | 128 | 128 | 16,384 |
| Chinchilla 70B | 80 | 64 | 128 | 8,192 |
Employs advanced training algorithms designed to minimize redundant computations — improved data sampling, gradient accumulation, and adaptive learning rates for faster convergence with less compute.
Integrates more efficient attention mechanisms and optimized layer configurations, maintaining high performance with fewer computational resources and lower energy usage.
Chinchilla Scaling Law
Detailed in Hoffmann et al.'s paper of the same name, the Chinchilla Scaling Law addresses the optimal balance between model size, number of training tokens, and compute power to maximize performance within a given compute budget.
Models with more parameters require more computational resources. More parameters necessitate more powerful, expensive hardware — increasing cost via GPU/TPU requirements and longer training times.
To achieve compute-optimal training, model size and the number of training tokens should scale equally — for every doubling of model size, training tokens should also double.
Many current LLMs are undertrained because they use a constant amount of training data despite increasing model sizes — an imbalance that leads to suboptimal performance.
arxiv.org/abs/2203.15556 — Jordan Hoffmann, Sebastian Borgeaud, Arthur Mensch, Elena Buchatskaya, Trevor Cai, Eliza Rutherford, Diego de Las Casas, Lisa Anne Hendricks, Johannes Welbl, Aidan Clark, Tom Hennigan, Eric Noland, Katie Millican, George van den Driessche, Bogdan Damoc, Aurelia Guy, Simon Osindero, Karen Simonyan, Erich Elsen, Jack W. Rae, Oriol Vinyals, Laurent Sifre
Open-Source Training Datasets
Comprehensive Wikipedia article corpus. Used by GPT-3, BERT, T5, RoBERTa, ELECTRA.
wikipedia.org →Common Objects in Context — image dataset with context descriptions.
Vast repository of web page data. Used by GPT-3, GPT-2, GPT-Neo, BERT, T5.
commoncrawl.org →The largest public-domain dataset released for training LLMs.
huggingface.co →Internal OpenAI corpus scraped with emphasis on document quality.
Conversations and discussions from Reddit. Used by GPT-3.
Platform providing access to multiple datasets. Used by GPT-3, BERT, RoBERTa.
Responsible Open-science Open-collaboration Text Sources — used by the 176B-parameter BLOOM model.
Stanford Question Answering Dataset for QA tasks.
Court Listener, Federal Register, State Codes, Congressional Hearings, and more.
huggingface.co →Large-scale adversarial dataset for grounded commonsense inference.
Workshop on Machine Translation datasets. Used by MarianMT, T5.
The Pile
The Pile is an 825 GiB English text corpus targeted at training large-scale language models, constructed from 22 diverse, high-quality subsets derived from academic and professional sources. Models trained on it improve significantly over both raw Common Crawl and CC-100 across all its components, while also improving downstream evaluation performance.
| Component | Raw Size (GB) | Weight (%) | Epochs | Size (GB) | Mean Doc Size (KB) |
|---|---|---|---|---|---|
| Pile-CC | 227.12 | 18.11 | 1 | 227.12 | 4.33 |
| PubMed Central | 90.27 | 14.40 | 2 | 180.55 | 30.55 |
| Books3† | 100.96 | 12.07 | 1.5 | 151.44 | 538.36 |
| OpenWebText2 | 62.77 | 10.01 | 2 | 125.54 | 3.85 |
| ArXiv | 56.21 | 8.96 | 2 | 112.42 | 46.61 |
| Github | 95.16 | 7.59 | 1 | 95.16 | 5.25 |
| FreeLaw | 51.15 | 6.12 | 1.5 | 76.73 | 15.06 |
| Stack Exchange | 32.20 | 5.13 | 2 | 64.39 | 2.16 |
| USPTO Backgrounds | 22.90 | 3.65 | 2 | 45.81 | 4.08 |
| PubMed Abstracts | 19.26 | 3.07 | 2 | 38.53 | 1.30 |
| Gutenberg (PG-19)† | 10.88 | 2.17 | 2.5 | 27.19 | 398.73 |
| OpenSubtitles† | 12.98 | 1.55 | 1.5 | 19.47 | 30.48 |
| Wikipedia (en)† | 6.38 | 1.53 | 3 | 19.13 | 1.11 |
| DM Mathematics† | 7.75 | 1.24 | 2 | 15.49 | 8.00 |
| Ubuntu IRC | 5.52 | 0.88 | 2 | 11.03 | 545.48 |
| BookCorpus2 | 6.30 | 0.75 | 1.5 | 9.45 | 369.87 |
| EuroParl† | 4.59 | 0.73 | 2 | 9.17 | 68.87 |
| HackerNews | 3.90 | 0.62 | 2 | 7.80 | 4.92 |
| YoutubeSubtitles | 3.73 | 0.60 | 2 | 7.47 | 22.55 |
| PhilPapers | 2.38 | 0.38 | 2 | 4.76 | 73.37 |
| NIH ExPorter | 1.89 | 0.30 | 2 | 3.79 | 2.11 |
| Enron Emails† | 0.88 | 0.14 | 2 | 1.76 | 1.78 |
| The Pile (Total) | 825.18 | 100 | — | 1254.20 | 5.91 |
To enable easier compliance with local laws, the Pile reproduction code is available and can exclude certain components inappropriate for a given user — undertaken at the component level, since exact per-text copyright metadata isn't available.
arxiv.org/abs/2101.00027v1 — Dec 2020 · Leo Gao, Stella Biderman, Sid Black, Laurence Golding, Travis Hoppe, Charles Foster, Jason Phang, Horace He, Anish Thite, Noa Nabeshima, Shawn Presser, Connor Leahy
Databricks
An open, general-purpose LLM created by Databricks with a fine-grained mixture-of-experts architecture, released March 27, 2024.
An open-source LLM developed by Databricks to democratize access to high-performing language models, released April 12, 2023.
Benchmarks for Evaluating LLM Performance
204 language tasks covering a range of topics and languages, not fully solvable by current models.
Comprehensive evaluation categorizing potential use cases and metrics, adopting a multi-metric approach across core scenarios.
Nine diverse NLP tasks evaluating models' understanding and generalization across domains.
An extension of GLUE with additional tasks focused on reasoning and coreference resolution.
Stanford Question Answering Dataset. 1.1 requires finding exact answers in text; 2.0 adds unanswerable questions to test model understanding.
Massive Multitask Language Understanding — 57 exam-like tasks spanning elementary mathematics, US history, computer science, law, and more.
Decomposes coarse-level scoring into skill-set-level scoring for each instruction — model-based evaluation with comparison and correlation analysis.
COPA: Choice of Plausible Alternatives. WiC: a binary classification benchmark evaluating context-sensitive word embeddings across two contexts per target word.
HELM
Benchmarks like SuperGLUE, EleutherAI LM Harness, and BIG-bench differ in their selection of scenarios and metrics, each with varying priorities and transparency. HELM aims for holistic evaluation by explicitly detailing the relationship between intended and actual evaluations through a top-down taxonomy of scenarios and metrics.
HELM implements a core set of 16 scenarios across tasks (question answering, information retrieval, summarization, toxicity detection) and domains (news, books), currently focused on English.
Seven categories of metrics — accuracy, calibration, robustness, fairness, bias, toxicity, efficiency — cover 98 of 112 possible scenario-metric pairs (87.5%).
arxiv.org/abs/2211.09110 — Holistic Evaluation of Language Models
LLM Benchmark for CRM
Salesforce developed the first LLM benchmark for CRM to assess the efficacy of generative AI models for business applications — evaluating LLMs for sales and service use cases across accuracy, cost, speed, and trust & safety, based on real CRM data and expert evaluations. What sets it apart: human evaluations by both Salesforce employees and actual external customers, on real-world datasets from Salesforce and customer operations.
Some use cases require over ½ million calls per year. If a model is at the right cost, accuracy can be increased if needed — shown as high/medium/low.
Also known as latency — critical for real-time use cases, though some are asynchronous. Defined as seconds needed for a full LLM response.
Average of Safety, Privacy, Truthfulness, and CRM Fairness — how often the LLM avoids unsafe answers, avoids revealing private info, stays accurate, and returns unbiased results across account/gender perturbations.
Word Embeddings
The initial phase of training transformer-based models: learning general language representations from a large and diverse corpus of text data.
TF-IDF
1972
Bag of Words
Foundational
Word2Vec
2013
GloVe
2014
RNNs / LSTM
2015
Transformers
2017
BERT / GPT
2018
The NLP evolution strip that recurs across this section of the deck.
A foundational text-encoding technique originating in the early 1950s: text is represented as an unordered collection of words, disregarding grammar and word order. A vocabulary is built from the entire corpus, and each document becomes a vector indicating the frequency (or presence/absence) of each vocabulary word. This transforms text into a numerical format suitable for ML algorithms, but it can't capture semantic relationships between words.
"The cat sat on the mat."
"The dog lay on the rug."
["The","cat","sat","on","the","mat"]
["The","dog","lay","on","the","rug"]
| Sent. | The | cat | sat | on | the | mat | dog | lay | rug |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 2 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 |
Word2Vec Encoding
Word2Vec, developed by Mikolov et al. at Google in 2013, is a highly influential method for learning word embeddings from large text corpora — transforming words into continuous vector representations that capture semantic relationships and syntactic properties. Words are represented as dense vectors in a high-dimensional space, typically 50 to 300 dimensions, enabling mathematical operations like dot products and vector addition.
CBOW architecture — a shallow, two-layer network. Input receives context words; the hidden layer averages context-word vectors; the output softmax predicts the target word.
Word2Vec Embeddings
Word embeddings are a fundamental component of LLMs, mapping words or phrases from a vocabulary to vectors of continuous numbers. These vectors capture semantic meanings and relationships, enabling models to perform NLP tasks more effectively. Words with similar meanings sit closer together in the vector space — "king" and "queen" are closer to each other than "king" and "apple."
Illustrative 2D projection of a high-dimensional embedding space — not the deck's original coordinates, but the relationship it depicts: gender and royalty as roughly consistent directions across word pairs.
Vector operations capture analogies — the offset between "man" and "woman" is roughly the same as the offset between "king" and "queen."
Context window size trades off syntactic vs. semantic information; dimensionality trades off nuance vs. compute; and a larger, more diverse corpus produces embeddings that generalize better.
Sequence2Sequence Encoding
Seq2Seq networks, introduced by Sutskever, Vinyals, and Le in 2014, transform sequences from one domain into sequences in another — making them effective for machine translation, text summarization, and dialogue systems. They typically consist of an encoder and a decoder, often implemented with RNNs, LSTMs, or more recently, transformers.
A single LSTM cell — forget, input, and output gates (σ) regulate what the cell state Cₜ keeps, adds, and exposes as the hidden state hₜ.
Encoder → thought vector → decoder. The encoder compresses the input sequence into a fixed-length context vector; the decoder generates the output sequence one token at a time from it.
Processes the input sequence and converts it into a fixed-length context vector capturing information about the entire input. In RNN-based models, a series of RNN cells take input tokens one at a time, updating the hidden state at each step — the final hidden state is the context vector.
Generates the output sequence from the encoder's context vector, as a sequence of RNN, LSTM, or Transformer blocks. At each step, it predicts the next token based on the current hidden state and previously generated tokens.
arxiv.org/abs/1409.3215 — Ilya Sutskever, Oriol Vinyals, Quoc V. Le
Transformer Multi-Head Self-Attention
Transformer architectures surpass LSTMs and RNNs on three fronts: parallelization (self-attention processes entire sequences simultaneously, rather than one token at a time), long-range dependencies (self-attention attends to all words in a sequence at once, avoiding the vanishing-gradient problems that limit RNNs), and attention mechanisms (multi-head self-attention is inherently integrated into the architecture, not bolted on).
The Transformer (Vaswani et al., 2017) — encoder stack (left, blue) and decoder stack (right, red), each repeated N× (N=6 in the original paper). The decoder's second attention block attends over the encoder's output.
Encoder: a stack of N=6 identical layers, each with a multi-head self-attention sub-layer and a position-wise feed-forward sub-layer, each wrapped in a residual connection followed by layer normalization: LayerNorm(x + Sublayer(x)). All sub-layers and embedding layers output dimension d_model = 512.
Decoder: also a stack of N=6 identical layers, adding a third sub-layer that performs multi-head attention over the encoder's output. The self-attention sub-layer is masked to prevent positions from attending to subsequent positions, preserving the auto-regressive property.
Attention Is All You Need
Vaswani et al.'s 2017 paper introduces the Transformer, a neural network architecture that relies entirely on attention mechanisms, dispensing with recurrence and convolutions entirely — a paradigm shift demonstrating how self-attention can significantly enhance the efficiency and performance of sequence transduction tasks like machine translation.
arxiv.org/abs/1706.03762 — Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin
BERT
BERT, developed by Google AI in 2018, uses a transformer-based encoder-only structure, reading text bidirectionally to capture context from both sides of a word. It leverages self-attention across 12 layers (BERT Base) or 24 layers (BERT Large), each with multiple attention heads, feed-forward networks, and residual connections with layer normalization. Its open-source release significantly influenced RoBERTa, ALBERT, and DistilBERT.
arxiv.org/abs/1810.04805 — Jacob Devlin, Ming-Wei Chang, Kenton Lee, Kristina Toutanova
Transformer Types
Tokenization
Several advanced tokenization methods are widely used in transformer architectures to address large vocabularies, rare words, and out-of-vocabulary terms.
Treats input text as a raw byte stream with no pre-tokenization, using a data-driven approach to generate subword units (BPE or unigram language model). Handles multiple languages and scripts.
Iteratively merges the most frequent pairs of characters or character sequences to form a fixed-size vocabulary, balancing manageable vocabulary size with handling rare/OOV words.
Similar to BPE but uses a probabilistic approach to merge tokens, maximizing the likelihood of training data given the vocabulary. Originally built for Google Translate; now widely used in BERT.
CTRL
CTRL, developed by Salesforce in 2019, is a 1.63-billion-parameter conditional transformer language model trained on a dataset containing control codes that govern style, content, and task-specific behavior — enabling fine-grained control over the model's output. Control codes were derived from structure that naturally co-occurs with raw text, preserving the advantages of unsupervised learning while adding explicit control, and enabling model-based source attribution over training data.
arxiv.org/abs/1909.05858 — Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, Caiming Xiong, Richard Socher
Retrieval Augmented Generation
RAG is a hybrid NLP approach that combines the strengths of retrieval-based methods and generative models to enhance the quality and relevance of generated text.
RAG pipeline: the user question is embedded, matched against a vector store of chunked, indexed, embedded source text, and the relevant chunks are combined with the question in a prompt template before the LLM generates a sourced answer.
A large corpus or database — structured or unstructured — from which relevant information is retrieved. Algorithms like TF-IDF, BM25, or neural retrieval methods (e.g. Dense Passage Retrieval) identify and rank the most relevant documents or passages.
The input query is converted into embeddings using models like BERT or other transformer-based encoders, so it can be effectively matched against the knowledge base — capturing semantic meaning and context to aid accurate retrieval.
Retrieved passages are integrated with the input query — concatenated or merged via attention mechanisms. A generative model (GPT-3, T5, BART) processes the combined input to generate a coherent, contextually relevant response.
RAG often includes mechanisms to iteratively refine retrieval and generation — multiple rounds of retrieval and generation, with re-ranking of retrieved passages based on relevance to the generated context.
Vector Database
Vector databases are a specialized class of databases designed to handle and query high-dimensional vector representations of data — essential for image recognition, NLP, and recommendation systems, where retrieval is based on vector similarity rather than exact match.
Raw data — text, images, audio — is collected and preprocessed for quality and consistency: tokenization, normalization, and stop-word removal for text; resizing, normalization, and augmentation for images.
Preprocessed data passes through models like BERT (text) or ResNet (images) to generate high-dimensional feature vectors representing each data point in a continuous vector space.
Vectors are indexed for efficient retrieval, alongside metadata like identifiers and attributes. ANN indexing methods let the database quickly find vectors similar to a given query vector.
Content passes through an embedding model and an indexer, producing a fixed-length array of floating-point numbers:
Approximate Nearest Neighbor (ANN) algorithms, tree-based algorithms, and hybrid/composite approaches, each trading off accuracy, speed, and storage differently.
Hierarchical Navigable Small World — a graph-based algorithm building a hierarchical network of vectors, each layer a navigable small-world graph.
Logarithmic-time search with high accuracy.
Real-time search — recommendation systems, image retrieval.
Divides vectors into smaller sub-vectors, quantizes each independently, and encodes into shorter codes.
Balances storage efficiency and search speed.
Large-scale search requiring efficient storage.
Locally Sensitive Hashing — hashes input vectors so similar vectors land in the same bucket; multiple hash functions improve accuracy.
Fast similarity search with sub-linear query times.
High-dimensional spaces — plagiarism detection, large-scale NN search.
A graph where each node connects to its k nearest neighbors; the search explores the graph to find approximate nearest neighbors.
Balances accuracy and efficiency.
Applications needing a speed/accuracy trade-off.
A binary tree recursively partitioning the data space into nested orthogonal regions, effective for low-dimensional spaces.
Efficient range queries and NN search in low-dimensional data.
Spatial databases, organizing k-dimensional points.
Organizes data into a tree where each node represents a cluster of points within a hypersphere.
Efficient NN search for high-dimensional data.
Clustering and classification tasks.
Approximate Nearest Neighbors Oh Yeah — builds a forest of random projection trees, similar to KD-Trees but optimized for approximate NN search.
Memory-efficient, fast query times.
Recommendation systems — e.g. Spotify's music recommendations.
Facebook AI Similarity Search — a library integrating multiple ANN algorithms (HNSW, PQ, LSH) for optimized speed and accuracy.
Highly flexible, efficient, handles large-scale datasets.
Image similarity search, large-scale information retrieval.
LangChain
LangChain streamlines and enhances the operations of large language models, integrating components and tools for efficient training, fine-tuning, and deployment across diverse NLP tasks. It provides robust support for modular workflows, letting practitioners build and customize pipelines for text generation, summarization, question answering, and more.
Build applications using LangChain's open-source building blocks and components. Hit the ground running with third-party integrations and templates.
Use LangSmith to inspect, monitor, and evaluate chains, so you can continuously optimize and deploy with confidence.
Turn any chain into an API with LangServe.
References
Transformer Architectures
Embeddings
Proprietary Large Language Models
Datasets
Training Cost
Evaluating Model Performance
Tutorials
Blogs