Skip to content

Language models, retrieval, prompting, and language adaptation · Autoregressive and open-weight model families · LNG033 · Model

GPT autoregressive language-model family

Uses causal language modeling to generate text and perform tasks described in a prompt. GPT-1/2/3 historical size and training generations are consolidated here; prompt adaptation is distinct from parameter updates.

Partly runs in CodeSplash Component demo, not a trained model CodeSplash's own run

In CodeSplash

A CodeSplash method covers part of this entry; some options or variants aren't built 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 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

Uses causal language modeling to generate text and perform tasks described in a prompt. GPT-1/2/3 historical size and training generations are consolidated here; prompt adaptation is distinct from parameter updates.

Question / objective

What next-token distribution supports generation and prompt-conditioned task behavior?

Architecture / computational structure

A causal decoder with token/position representations and vocabulary projection learns autoregressive weights. Model dimensions, context length, data mix, and decoding settings are hyperparameters; prompt examples are conditioning data, not learned weights.

Assumptions

Next-token prediction rewards distributional fit, not factual truth or calibrated reasoning.

Formula / computational definition

pθ(x1:T)=∏t=1Tpθ(xt∣x<t),L=−1T∑t=1Tlog⁡pθ(xt∣x<t).p_\theta(x_{1:T})=\prod_{t=1}^{T}p_\theta(x_t\mid x_{<t}),\qquad \mathcal L=-\frac1T\sum_{t=1}^{T}\log p_\theta(x_t\mid x_{<t}).

p_theta(x_1:T)=product_t p_theta(x_t|x_<t); training minimizes average next-token negative log likelihood. At inference, a prompt fixes the initial context and decoding selects or samples additional tokens.

Parameters and notation

Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Vocabulary, context budget, layer/width configuration, data mixture, optimizer schedule, prompt examples, temperature, and stopping rules.

Fitting, fine-tuning, and adaptation

Continue next-token training on domain text or supervised instruction examples with correct response masking. Freeze the base for LoRA/adapters where supported, or full-fine-tune with conservative rates and held-out tasks. Track general-language loss and factuality to detect narrow-domain forgetting.

How to use and calibrate

Use held-out loss with identical tokenization, task-specific accuracy, prompt sensitivity, contamination checks, factuality, and computational 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

Generate structured explanations from a prompt while comparing zero-shot and few-shot conditioning.

Interpretation / pitfalls

Watch out

Few-shot examples can introduce order effects and contamination; likelihoods depend on tokenizer and label wording. 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: Open GPT-style checkpoints can use Transformers causal-language-model interfaces; historical proprietary checkpoints may not be reproducible or available. R can bridge supported Python implementations. The native example computes causal sequence likelihood and perplexity, not a hosted service call.

Example scope: Autoregressive token loss and perplexity from supplied GPT-style conditional probabilities.

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.

Python

Component demo, not a trained model — Autoregressive token loss and perplexity from supplied GPT-style conditional probabilities.

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)
p = [0.6,0.5,0.8,0.7]
loss = nll(p)/len(p)
print({"nll": loss, "perplexity": math.exp(loss)})
R

Component demo, not a trained model — Autoregressive token loss and perplexity from supplied GPT-style conditional probabilities.

Shared setup for this chapter
softmax <- function(x) {
  shifted <- exp(x-max(x))
  shifted/sum(shifted)
}
p <- c(0.6,0.5,0.8,0.7)
loss <- -mean(log(p))
print(c(nll=loss, perplexity=exp(loss)))

Sources

From the CodeSplash reference, entry LNG033.