Language models, retrieval, prompting, and language adaptation · Long-context and retrieval-augmented language · LNG057 · Model
Contriever
Learns dense retrieval representations from unlabeled text through contrastive training. Different views or spans of the same document provide positive pairs, reducing dependence on human relevance labels for…
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran here in one language.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Learns dense retrieval representations from unlabeled text through contrastive training. Different views or spans of the same document provide positive pairs, reducing dependence on human relevance labels for initialization.
Question / objective
Can unlabeled document views initialize useful dense retrieval representations?
Architecture / computational structure
A contrastive encoder and momentum/negative-memory mechanism learn pooled vectors from augmented text. Learned encoder weights are parameters; augmentation, momentum, temperature, and negative memory settings are hyperparameters.
Assumptions
Shared-document spans need not express the same information, while negatives can contain related or relevant passages.
Formula / computational definition
For query-like view q and positive key k+, use InfoNCE: -log exp(sim(q,k+)/tau)/sum_k exp(sim(q,k)/tau). Momentum encoders and large negative sets support representation learning in the described approach.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Text augmentation/cropping, temperature tau, queue or negative-set size, momentum update, encoder, and later supervised adaptation.
Fitting, fine-tuning, and adaptation
Pretrain on unlabeled text with controlled cropping, then optionally fine-tune on labeled relevance pairs. Freeze an encoder baseline before full or supported adapter updates; reindex after changes. Validate zero-shot transfer separately from supervised gains and inspect false negatives and representation collapse.
How to use and calibrate
Test zero-shot retrieval across datasets, compare later fine-tuning separately, and report recall, ranking quality, domain shift, and indexing cost. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Bootstrap semantic retrieval in a domain without relevance annotations.
Interpretation / pitfalls
Watch out
Unsupervised pretraining does not guarantee task-specific relevance or multilingual alignment. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use the authors' encoder checkpoints and preprocessing; Python implementations expose embeddings for indexing. R can bridge with reticulate and evaluate natively. The toy contrastive loss demonstrates the objective and temperature effect without reproducing a momentum-training pipeline.
Example scope: Contriever InfoNCE loss and the influence of temperature on a fixed similarity vector.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Contriever InfoNCE loss and the influence of temperature on a fixed similarity vector.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
similarities = [0.8,0.5,0.2]
losses = {tau:-math.log(softmax([s/tau for s in similarities])[0]) for tau in [0.1,0.5,1.0]}
print(losses)
Component demo, not a trained model — Contriever InfoNCE loss and the influence of temperature on a fixed similarity vector.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
similarities <- c(0.8,0.5,0.2)
losses <- sapply(c(0.1,0.5,1),function(tau) -log(softmax(similarities/tau)[1]))
print(losses)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG057.