Language models, retrieval, prompting, and language adaptation · Contextual and sentence encoders · LNG011 · Training method
RoBERTa
A robustly optimized BERT pretraining recipe showing that data, batching, masking, and training duration can explain large performance differences.
In CodeSplash
A CodeSplash method covers part of this entry; some options or variants aren't built yet.
- Text encoder (MiniLM + linear head) Not verified yet
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Partly runs in CodeSplash
- 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
A robustly optimized BERT pretraining recipe showing that data, batching, masking, and training duration can explain large performance differences. It is documented as a training-method/model family, not a fundamentally different attention mechanism.
Question / objective
How much can BERT-style representation quality improve through a stronger pretraining recipe?
Architecture / computational structure
The underlying bidirectional encoder remains BERT-like, while data scale, dynamic masking, training duration, and removal of next-sentence prediction alter optimization. Learned encoder/head weights remain parameters; recipe choices are hyperparameters.
Assumptions
More compute and data confound comparisons with smaller BERT experiments.
Formula / computational definition
Optimize masked-token cross-entropy over dynamically sampled masks, L=-E_M sum_{t in M} log p_theta(x_t|x_notM). The original recipe omits BERT's next-sentence objective and changes data/training choices.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Corpus composition, batch size, training steps, masking generation, byte-level subword vocabulary, sequence length, and fine-tuning settings.
Fitting, fine-tuning, and adaptation
Use the correct tokenizer and checkpoint; adapt through a task head, continued masked-language modeling, adapters, or carefully tuned full fine-tuning. Compare with BERT under controlled data and compute when studying the recipe. Monitor validation accuracy, calibration, and general-domain retention.
How to use and calibrate
Compare equal-data/equal-compute conditions where possible and report task performance with split and hyperparameter-selection discipline. 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
Establish a strong encoder baseline for document classification before choosing larger generative models.
Interpretation / pitfalls
Watch out
Domain mismatch and vocabulary fragmentation can persist despite stronger pretraining; embeddings still need suitable pooling or sentence-level training. 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 documented RoBERTa checkpoints with Transformers, selecting an appropriate encoder/task head. R reticulate provides the same implementation; custom training should reproduce the recipe rather than merely substitute a model name.
Example scope: Two dynamic-mask selections for the same sentence; deterministic illustration, not exact pretraining.
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 — Two dynamic-mask selections for the same sentence; deterministic illustration, not exact pretraining.
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)
tokens = ["a", "small", "model", "learns"]
mask_sets = [{1}, {2}]
views = [["<mask>" if i in mask else word for i, word in enumerate(tokens)] for mask in mask_sets]
print(views)
Component demo, not a trained model — Two dynamic-mask selections for the same sentence; deterministic illustration, not exact pretraining.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
tokens <- c("a","small","model","learns")
mask_sets <- list(2L, 3L)
views <- lapply(mask_sets, function(idx) {x <- tokens; x[idx] <- "<mask>"; x})
print(views)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG011.