Language models, retrieval, prompting, and language adaptation · Autoregressive and open-weight model families · LNG041 · Model
Gemma model family
Groups documented Gemma open-weight models, with the Gemma 3 report describing multimodal capabilities and attention/context design. Family members differ in size and modality;
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 in Python and R here, and they agree.
- 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
Groups documented Gemma open-weight models, with the Gemma 3 report describing multimodal capabilities and attention/context design. Family members differ in size and modality; a text-only member must not be described as supporting images merely because the family does.
Question / objective
How does a specific Gemma checkpoint trade local/global attention, context, and multimodal capability?
Architecture / computational structure
The selected model contains release-specific decoder attention and, where supported, image-processing components. Learned language/vision weights are parameters; attention schedule, image resolution, context budget, and precision are configuration controls.
Assumptions
Nominal context length does not establish uniform retrieval accuracy across positions.
Formula / computational definition
Text generation uses conditional autoregressive likelihood. The reported architecture combines local and global attention layers; multimodal versions condition language generation on image representations as well as text.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Exact checkpoint, local/global attention schedule, context budget, image preprocessing when supported, chat template, quantization, and decoding controls.
Fitting, fine-tuning, and adaptation
Adapt only supported modules using task-appropriate language or multimodal loss; freeze the vision encoder initially when image labels are scarce, or use verified adapters. Validate grounded answers, text-only retention, long-context behavior, and checkpoint-specific preprocessing rather than assuming family-wide compatibility.
How to use and calibrate
Separate text and image tasks, long-context retrieval, grounded factuality, memory, and inference latency; report exact model and precision. 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
Build an image-and-text document assistant using a checkpoint whose image support is explicitly documented.
Interpretation / pitfalls
Watch out
Multimodal behavior depends on image resolution and preprocessing, and weights may require specific usage terms. 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 Transformers support or official reference implementations matched to the selected checkpoint. R generally bridges Python through reticulate. The native mask example illustrates mixed local/global attention without implying a runnable Gemma checkpoint.
Example scope: Mixed local/global causal masks as a conceptual Gemma 3 design component; no exact layer schedule claimed.
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 — Mixed local/global causal masks as a conceptual Gemma 3 design component; no exact layer schedule claimed.
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)
n, window = 5, 2
local = [[int(max(0,i-window+1) <= j <= i) for j in range(n)] for i in range(n)]
global_causal = [[int(j <= i) for j in range(n)] for i in range(n)]
print({"local_edges": sum(map(sum,local)), "global_edges": sum(map(sum,global_causal))})
Component demo, not a trained model — Mixed local/global causal masks as a conceptual Gemma 3 design component; no exact layer schedule claimed.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
n <- 5L; window <- 2L
local <- outer(0:(n-1),0:(n-1),function(i,j) as.integer(j <= i & j >= pmax(0,i-window+1)))
global_causal <- outer(0:(n-1),0:(n-1),function(i,j) as.integer(j <= i))
print(c(local_edges=sum(local),global_edges=sum(global_causal)))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG041.