— that he noticed additional solely by standing on the shoulders of giants — captures a timeless fact about science. Each breakthrough rests on numerous layers of prior progress, till sooner or later … all of it simply works. Nowhere is that this extra evident than within the current and ongoing revolution in pure language processing (NLP), pushed by the Transformers structure that underpins most generative AI techniques immediately.
“If I’ve seen additional, it’s by standing on the shoulders of Giants.”
— Isaac Newton, letter to Robert Hooke, February 5, 1675 (Previous Type calendar; 1676 New Type)
On this article, I tackle the function of a tutorial Sherlock Holmes, tracing the evolution of language modelling.
A language mannequin is an AI system skilled to foretell and generate sequences of phrases primarily based on patterns realized from giant textual content datasets. It assigns chances to phrase sequences, enabling functions from speech recognition and machine translation to immediately’s generative AI techniques.
Like all scientific revolutions, language modelling didn’t emerge in a single day however builds on a wealthy heritage. On this article, I give attention to a small slice of the huge literature within the subject. Particularly, our journey will start with a pivotal earlier expertise — the Relevance-Based Language Models of Lavrenko and Croft — which marked a step change within the efficiency of Data Retrieval techniques within the early 2000s and continues to go away its mark in TREC competitions. From there, the path results in 2017, when Google printed the seminal Attention Is All You Need paper, unveiling the Transformers structure that revolutionised sequence-to-sequence translation duties.
The important thing hyperlink between the 2 approaches is, at its core, fairly easy: the highly effective thought of consideration. Simply as Lavrenko and Croft’s Relevance Modelling estimates which phrases are more than likely to co-occur with a question, the Transformer’s consideration mechanism computes the similarity between a question and all tokens in a sequence, weighting every token’s contribution to the question’s contextual that means.
In each instances the eye mechanism acts as a mushy probabilistic weighting mechanism, giving each strategies their uncooked representational energy.
Each fashions are generative frameworks over textual content, differing primarily of their scope: RM1 fashions quick queries from paperwork, transformers mannequin full sequences.
Within the following sections, we are going to discover the background of Relevance Fashions and the Transformer structure, highlighting their shared foundations and clarifying the parallels between them.
Relevance Modelling — Introducing Lavrenko’s RM1 Combination Mannequin
Let’s dive into the conceptual parallel between Lavrenko & Croft’s Relevance Modelling framework in Data Retrieval and the Transformer’s consideration mechanism. Each emerged in numerous domains and eras, however they share the identical mental DNA. We’ll stroll via the background on Relevance Fashions, earlier than outlining the important thing hyperlink to the next Transformer structure.
When Victor Lavrenko and W. Bruce Croft launched the Relevance Mannequin within the early 2000s, they supplied a chic probabilistic formulation for bridging the hole between queries and paperwork. At their core, these fashions begin from a easy thought: assume there exists a hidden “relevance distribution” over vocabulary phrases that characterises paperwork a consumer would contemplate related to their question. The duty then turns into estimating this distribution from the noticed knowledge, specifically the consumer question and the doc assortment.
The primary Relevance Modelling variant — RM1 (there have been two different fashions in the identical household, not highlighted intimately right here) — does this instantly by inferring the distribution of phrases prone to happen in related paperwork given a question, basically modelling relevance as a latent language mannequin that sits“behind” each queries and paperwork.

with the posterior chance of a doc d given a question q given by:

That is the basic unigram language mannequin with Dirichlet smoothing proposed within the authentic paper by Lavrenko and Croft. To estimate this relevance mannequin, RM1 makes use of the top-retrieved paperwork as pseudo-relevant suggestions (PRF) — it assumes the highest-scoring paperwork are prone to be related. Which means that no expensive relevance judgements are required, a key benefit of Lavrenko’s formulation.

To construct up an instinct into how the RM1 mannequin works, we’ll code it up step-by-step in Python, utilizing a easy toy doc corpus consisting of three “paperwork”, outlined beneath, with a question “cat”.
import math
from collections import Counter, defaultdict
# -----------------------
# Step 1: Instance corpus
# -----------------------
docs = {
"d1": "the cat sat on the mat",
"d2": "the canine barked on the cat",
"d3": "canine and cats are buddies"
}
# Question
question = ["cat"]
Subsequent — for the needs of this toy instance IR scenario— we frivolously pre-process the doc assortment, by splitting the paperwork into tokens, figuring out the rely of every token inside every doc, and defining the vocabulary:
# -----------------------
# Step 2: Preprocess
# -----------------------
# Tokenize and rely
doc_tokens = {d: doc.break up() for d, doc in docs.objects()}
doc_lengths = {d: len(toks) for d, toks in doc_tokens.objects()}
doc_term_counts = {d: Counter(toks) for d, toks in doc_tokens.objects()}
# Vocabulary
vocab = set(w for toks in doc_tokens.values() for w in toks)
If we run the above code we are going to get the next output, with 4 easy knowledge constructions holding the knowledge we have to compute the RM1 distribution of relevance for any question.
doc_tokens = {
'd1': ['the', 'cat', 'sat', 'on', 'the', 'mat'],
'd2': ['the', 'dog', 'barked', 'at', 'the', 'cat'],
'd3': ['dogs', 'and', 'cats', 'are', 'friends']
}
doc_lengths = {
'd1': 6,
'd2': 6,
'd3': 5
}
doc_term_counts = {
'd1': Counter({'the': 2, 'cat': 1, 'sat': 1, 'on': 1, 'mat': 1}),
'd2': Counter({'the': 2, 'canine': 1, 'barked': 1, 'at': 1, 'cat': 1}),
'd3': Counter({'canine': 1, 'and': 1, 'cats': 1, 'are': 1, 'buddies': 1})
}
vocab = {
'the', 'cat', 'sat', 'on', 'mat',
'canine', 'barked', 'at',
'canine', 'and', 'cats', 'are', 'buddies'
}
If we have a look at the RM1 equation outlined earlier, we will break it up into key probabilistic parts. P(w|d) defines the chance distribution of the phrases w in a doc d. P(w|d) is normally computed utilizing Dirichlet prior smoothing (Zhai & Lafferty, 2001). This prior avoids zero chances for unseen phrases and balances document-specific proof with background assortment statistics. That is outlined as:

The above equation offers us a bag of phrases unigram mannequin for every of the paperwork in our corpus. As an apart, you possibly can think about how nowadays — with highly effective language fashions accessible of Hugging-face — we might swap out this formulation for e.g. a BERT-based variant, utilizing embeddings to estimate the distribution P(w|d).
In a BERT-based strategy to P(w|d), we will derive a doc embedding g(d) through imply pooling and a phrase embedding e(w), then mix them within the following equation:

Right here V denotes the pruned vocab (e.g., union of doc phrases) and 𝜏 is a temperature parameter. This might be step one on making a Neural Relevance Mannequin (NRM), an untouched and probably novel route within the subject of IR.
Again to the unique formulation: this prior formulation could be coded up in Python, as our first estimate of P(w|d):
# -----------------------
# Step 3: P(w|d)
# -----------------------
def p_w_given_d(w, d, mu=2000):
"""Dirichlet-smoothed language mannequin."""
tf = doc_term_counts[d][w]
doc_len = doc_lengths[d]
# assortment chance
cf = sum(doc_term_counts[dd][w] for dd in docs)
collection_len = sum(doc_lengths.values())
p_wc = cf / collection_len
return (tf + mu * p_wc) / (doc_len + mu)
Subsequent up, we compute the question probability beneath the doc mannequin — P(q|d):
# -----------------------
# Step 4: P(q|d)
# -----------------------
def p_q_given_d(q, d):
"""Question probability beneath doc d."""
rating = 0.0
for w in q:
rating += math.log(p_w_given_d(w, d))
return math.exp(rating) # return probability, not log
RM1 requires P(d|q), so we flip the chance — P(q|d) — utilizing Bayes rule:
def p_d_given_q(q):
"""Posterior distribution over paperwork given question q."""
# Compute question likelihoods for all paperwork
scores = {d: p_q_given_d(q, d) for d in docs}
# Assume uniform prior P(d), so proportionality is simply scores
Z = sum(scores.values()) # normalization
return {d: scores[d] / Z for d in docs}
We assume right here that the doc prior is uniform, and so it cancels. We additionally then normalize throughout all paperwork so the posteriors sum to 1:

Much like P(w|d), it’s value pondering how we might neuralise the P(d|q) phrases in RM1. A primary strategy could be to make use of an off-the-shelf cross- or dual-encoder mannequin (such because the MS MARCO–fine-tuned BERT cross-encoder) to embed the question and doc, produce a similarity rating, and normalize it with a softmax:

With P(d|q) and P(w|d) transformed to neural network-based representations, we will plug each collectively to get a easy preliminary model of a neural RM1 mannequin that may give us again P(w|q).
For the needs of this text — nevertheless — we are going to change again into the basic RM1 formulation. Let’s run the (non-neural, normal RM1) code thus far to see the output of the varied parts we’ve simply mentioned. Recall that our toy doc corpus is:
d1: "the cat sat on the mat"
d2: "the canine barked on the cat"
d3: "canine and cats are buddies"
Assuming Dirichlet smoothing (with μ=2000), the values might be very shut to the gathering chance of “cat” for the reason that paperwork are very quick. For illustration:
- d1: “cat” seems as soon as in 6 phrases → P(q|d1) is roughly 0.16
- d2: “cat” seems as soon as in 6 phrases → P(q|d2) is roughly 0.16
- d3: “cat” by no means seems → P(q|d3) is roughly 0 (with smoothing, a small >0 worth)
We now normalize this distribution to reach on the posterior distribution:
q)': 0.4997,
'P(d3
What’s the key distinction between P(d|q) and P(q|d)?
P(q|d) tells us how effectively the doc “explains” the question. If we think about that every doc is itself a mini language mannequin: if it had been producing textual content, how possible is it to supply the phrases we see within the question? This chance is excessive if the question phrases look pure beneath the paperwork phrase distribution. For instance, for question “cat”, a doc that actually mentions “cat” will give a excessive probability; one about “canine and cats” a bit much less; one about “Charles Dickens” near zero.
In distinction, the chance P(d|q) codifies how a lot we must always belief the doc given the question. This flips the attitude utilizing Bayes rule: now we ask, given the question, what’s the chance the consumer’s related doc is d?
So as an alternative of evaluating how effectively the doc explains the question, we deal with paperwork as competing hypotheses for relevance and normalise them right into a distribution over all paperwork. This offers us a rating rating changed into chance mass — the upper it’s, the extra possible this doc is related in comparison with the remainder of the gathering.
We now have all parts to complete our implementation of Lavrenko’s RM1 mannequin:
# -----------------------
# Step 6: RM1: P(w|R,q)
# -----------------------
def rm1(q):
pdq = p_d_given_q(q)
pwRq = defaultdict(float)
for w in vocab:
for d in docs:
pwRq[w] += p_w_given_d(w, d) * pdq[d]
# normalize
Z = sum(pwRq.values())
for w in pwRq:
pwRq[w] /= Z
return dict(sorted(pwRq.objects(), key=lambda x: -x[1]))
# -----------------------
We are able to now see that RM1 defines a chance distribution over the vocabulary that tells us which phrases are more than likely to happen in paperwork related to the question. This distribution can then be used for question enlargement, by including high-probability phrases, or for re-ranking paperwork by measuring the KL divergence between every doc’s language mannequin and the question’s relevance mannequin.
High phrases from RM1 for question ['cat']
cat 0.1100
the 0.1050
canine 0.0800
sat 0.0750
mat 0.0750
barked 0.0700
on 0.0700
at 0.0680
canine 0.0650
buddies 0.0630
In our toy instance, the time period “cat” naturally rises to the highest, because it matches the question instantly. Excessive-frequency background phrases like “the” additionally seem strongly, although in observe these could be filtered out as cease phrases. Extra apparently, content material phrases from paperwork containing “cat” (equivalent to sat, mat, canine, barked) are elevated as effectively. That is the facility of RM1: it introduces associated phrases not current within the question itself, with out requiring specific relevance judgments or supervision. Phrases distinctive to d3 (e.g., buddies, canine, cats) obtain small however nonzero chances due to smoothing.
RM1 defines a query-specific relevance mannequin, a language mannequin induced from the question, which is estimated by averaging over paperwork possible related to that question.
Having now seen how RM1 builds a query-specific language mannequin by reweighing doc phrases based on their posterior relevance, it’s arduous to not discover the parallel with what got here a lot later in deep studying: the eye mechanism in Transformers.
In RM1, we estimate a brand new distribution P(w|R, q) over phrases by combining doc language fashions, weighted by how possible every doc is related given the question. The Transformer structure does one thing relatively comparable: given a token (the “question”), it computes a similarity to all different tokens (the “keys”), then makes use of these scores to weight their “values.” This produces a brand new, context-sensitive illustration of the question token.
Lavrenko’s RM1 Mannequin as a “proto-Transformer”
The eye mechanism, launched as a part of the Transformer structure, was designed to beat a key weak point of earlier sequence fashions like LSTMs and RNNs: their quick reminiscence horizons. Whereas recurrent fashions struggled to seize long-range dependencies, consideration made it doable to instantly join any token in a sequence with every other, whatever the distance within the sequence.
What’s fascinating is that the arithmetic of consideration seems similar to what RM1 was doing a few years earlier. In RM1, as we’ve seen, we construct a query-specific distribution by weighting paperwork; in Transformers, we construct a token-specific illustration by weighting different tokens within the sequence. The precept is identical — assign chance mass to probably the most related context — however utilized on the token stage relatively than the doc stage.
Should you strip Transformers right down to their essence, the eye mechanism is basically simply RM1 utilized on the token stage.
This may be seen as a daring declare, so it’s incumbent upon us to offer some proof!
Let’s first dig a little bit deeper into the eye mechanism, and I defer to the incredible wealth of high-quality existing introductory material for a fuller and deeper dive.
Within the Transformer’s consideration layer — often called scaled dot-product consideration — given a question vector q, we compute its similarity to all different tokens’ keys okay. These similarities are normalized into weights via a softmax. Lastly, these weights are used to mix the corresponding values v, producing a brand new, context-aware illustration of the question token.
Scaled dot-product consideration is:

Right here, Q = question vector(s), Ok = key vectors (paperwork, in our analogy, V = worth vectors (phrases/options to be blended). The softmax is a normalised distribution over the keys.
Now, recall RM1 (Lavrenko & Croft 2001):

The eye weights in scaled dot-product consideration parallel the doc–question distribution P(d|q) in RM1. Reformulating consideration in per-query kind makes this connection specific:


The worth vector — v — in consideration could be considered equivalent to P(w|d) within the RM1 mannequin, however as an alternative of an specific phrase distribution, v is a dense semantic vector — a low-rank surrogate for the complete distribution. It’s successfully the content material we combine collectively as soon as we arrive on the relevance scores for every doc.
Zooming out to the broader Transformer structure, Multi-head consideration could be seen as working a number of RM1-style relevance fashions in parallel with completely different projections.
We are able to moreover draw additional parallels with the broader Transfomer structure.
- Strong Chance Estimation: For instance, we now have beforehand mentioned that RM1 wants smoothing (e.g., Dirichlet) to clean zero counts and keep away from overfitting to uncommon phrases. Equally, Transformers use residual connections and layer normalisation to stabilise and keep away from collapsing consideration distributions. Each fashions implement robustness in chance estimation when the info sign is sparse or noisy.
- Pseudo Relevance Suggestions: RM1 performs a single spherical of probabilistic enlargement via pseudo-relevance suggestions (PRF), proscribing consideration to the top-Ok retrieved paperwork. The PRF set features like an consideration context window: the question distributes chance mass over a restricted set of paperwork, and phrases are reweighed accordingly. Equally, transformer consideration is proscribed to the native enter sequence. Not like RM1, nevertheless, transformers stack many layers of consideration, each reweighting and refining token distributions. Deep consideration stacking can thus be seen as iterative pseudo-relevance suggestions — repeatedly pooling throughout associated context to construct richer representations.
The analogy between RM1 and the Transformer is summarised within the beneath desk, the place we tie collectively every element and draw hyperlinks between every:

RM1 expressed a strong however basic thought: relevance could be understood as weighting mixtures of content material primarily based on similarity to a question.
Almost 20 years later, the identical precept re-emerged within the Transformer’s consideration mechanism — now on the stage of tokens relatively than paperwork. What started as a statistical mannequin for question enlargement in Data Retrieval developed into the mathematical core of contemporary Giant Language Fashions (LLMs). It’s a reminder that stunning concepts in science hardly ever disappear; they journey ahead via time, reshaped and reinterpreted in new contexts.
Via the written phrase, scientists carry concepts throughout generations — quietly binding collectively waves of innovation — till, abruptly, a breakthrough emerges.
Typically the best concepts are probably the most highly effective. Who would have imagined that “consideration” might develop into the important thing to unlocking language? And but, it’s.
Conclusions and Remaining Ideas
On this article, we now have traced one department of the huge tree that’s language modelling, uncovering a compelling connection between the event of relevance fashions in early data retrieval and the emergence of Transformers in fashionable NLP. RM1 — ther first variant within the household of relevance fashions, was, in some ways, a proto-Transformer for IR — foreshadowing the mechanism that might later reshape how machines perceive language.
We even coded up a neural variant of the Relevance Mannequin, utilizing fashionable encoder-only fashions, thereby formally unifying previous (relevance mannequin) and current (transformer structure) in the identical formal probabilistic mannequin!
Initially, we invoked Newton’s picture of standing on the shoulders of giants. Allow us to shut with one other of his reflections:
“I have no idea what I’ll seem to the world, however to myself I appear to have been solely like a boy enjoying on the seashore, and diverting myself in at times discovering a smoother pebble or a prettier shell than atypical, while the nice ocean of fact lay all undiscovered earlier than me.” Newton, Isaac. Quoted in David Brewster, Memoirs of the Life, Writings, and Discoveries of Sir Isaac Newton, Vol. 2 (1855), p. 407.
I hope that you simply agree that the trail from RM1 to Transformers is simply such a discovery — a extremely polished pebble on the shore of a a lot larger ocean of AI discoveries but to return.
Disclaimer: The views and opinions expressed on this article are my very own and don’t symbolize these of my employer or any affiliated organizations. The content material is predicated on private expertise and reflection, and shouldn’t be taken as skilled or educational recommendation.
