n4nAI

Base models explained: raw next-token prediction

A base model is a raw language model trained only for next-token prediction. This explainer covers how it works, why it matters for engineers, and common misconceptions.

n4n Team6 min read1,235 words

Audio narration

Coming soon — every post will get a voice note here.

A base model is a language model trained exclusively on the next-token prediction objective across a large, diverse text corpus. It has no instruction tuning, no reinforcement learning from human feedback, and no conversational formatting — just the raw probability distribution over the next token given prior context. Understanding base models is essential because they are the foundation every instruct or chat model builds on, and they behave fundamentally differently from the aligned models most engineers interact with daily.

How base models work

The training objective is deceptively simple: given a sequence of tokens, predict the next one. Formally, for a sequence $x_1, x_2, …, x_{t-1}$, the model learns to maximize $P(x_t | x_{<t})$. At scale — trillions of tokens, hundreds of billions of parameters — this objective produces models that capture syntax, semantics, world knowledge, reasoning patterns, and the statistical structure of human language.

# Conceptual training loop for a base model
for batch in dataloader:
    input_ids = batch[:, :-1]      # all tokens except last
    target_ids = batch[:, 1:]      # all tokens except first
    
    logits = model(input_ids)      # [batch, seq_len, vocab_size]
    loss = cross_entropy(
        logits.view(-1, vocab_size),
        target_ids.view(-1)
    )
    loss.backward()
    optimizer.step()

No special tokens mark instructions, no system prompts, no chat templates. The model sees raw text: Wikipedia, Common Crawl, GitHub, books, arXiv. It learns to complete whatever pattern appears in the context window — whether that’s a Python function, a legal contract, a poem, or a dialogue.

The critical implication: a base model completes rather than answers. Give it a question, and it may continue with another question, a related paragraph, or a list of similar questions — whatever the training distribution suggests follows naturally.

Why base models matter for engineers

If you only ever call aligned chat endpoints, base models can seem irrelevant. They’re not. Three concrete reasons to understand them:

1. They’re the substrate for all downstream specialization. Every instruct model (Llama-3-Instruct, Qwen2.5-Instruct, Nemotron-3-Ultra) starts as a base model. The alignment layer — supervised fine-tuning on instruction/response pairs, then preference optimization — is thin relative to the base training compute. When an aligned model fails in a specific way (hallucination patterns, refusal behavior, style drift), the root cause often traces to the base model’s priors.

2. They’re better for certain tasks. Base models excel at open-ended generation, creative writing, code completion without chat formatting overhead, and tasks where you want the model to continue a pattern rather than respond to an instruction. Many retrieval-augmented generation pipelines work better with a base model that treats retrieved context as a prefix to continue, not as a question to answer.

3. They expose the model’s raw capabilities. Evaluating a base model tells you what the architecture and pre-training data actually learned. Aligned models can mask capabilities (via refusal) or create illusions of capability (via verbose but empty responses). Base model evals are the ground truth.

Concrete example: prompting a base model vs. an instruct model

Consider this prompt:

Write a Python function that computes the Fibonacci sequence up to n terms.

Instruct model response (typical):

def fibonacci(n):
    """Return Fibonacci sequence up to n terms."""
    if n <= 0:
        return []
    elif n == 1:
        return [0]
    
    sequence = [0, 1]
    for i in range(2, n):
        sequence.append(sequence[-1] + sequence[-2])
    return sequence

Base model completion (typical):

def fibonacci(n):
    if n <= 0:
        return []
    elif n == 1:
        return [0]
    elif n == 2:
        return [0, 1]
    
    fib = [0, 1]
    for i in range(2, n):
        fib.append(fib[i-1] + fib[i-2])
    return fib

# Test the function
print(fibonacci(10))
# Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

# Recursive version (less efficient)
def fib_recursive(n):
    if n <= 1:
        return n
    return fib_recursive(n-1) + fib_recursive(n-2)

The base model continued the pattern — it wrote the function, then added a test case, then provided an alternative implementation. It treated the prompt as the beginning of a code file, not an instruction to follow. This behavior is exactly what you want for code completion in an IDE. It’s exactly what you don’t want for a chatbot.

To get an instruct-style response from a base model, you must simulate the instruction format the model saw during pre-training — typically by framing as a completion problem:

### Instruction:
Write a Python function that computes the Fibonacci sequence up to n terms.

### Response:

This works because the base model has seen countless instruction/response pairs in its training data (StackOverflow, tutorials, documentation). It recognizes the pattern and completes it appropriately. But it’s fragile — the model may still drift, add extra sections, or fail to stop cleanly.

Common misconceptions

“Base models are just worse chat models”

False. They’re different models optimized for a different objective. A base model evaluated on chat benchmarks will score poorly because it doesn’t follow the chat format. But on perplexity, next-token prediction, or open-ended generation quality, it often outperforms its aligned counterpart — alignment inevitably narrows the output distribution.

“You can’t use base models in production”

You can, and people do. Code completion (GitHub Copilot’s original model was Codex, a GPT-3 base variant), text infilling, synthetic data generation, and certain RAG architectures all use base models in production. The key is framing your task as completion rather than instruction following.

“Base models have no safety guardrails”

True in the narrow sense — no RLHF refusal training. But they do have statistical guardrails. A model trained on the open internet has seen vast amounts of safe, helpful, constructive text. Its completions tend toward the norm of its training distribution. That’s not reliable safety for user-facing applications, but it’s not a chaotic free-for-all either. The real risk isn’t that a base model will spontaneously generate harm — it’s that it will complete a harmful prompt if the context leads there.

“Instruct tuning adds knowledge”

Instruct tuning adds behavior, not knowledge. The model’s factual knowledge, reasoning capacity, and linguistic competence come almost entirely from pre-training. Instruction tuning teaches the model to package that capability into a specific interaction format. This is why base model perplexity correlates strongly with downstream task performance after alignment — the ceiling is set during pre-training.

“All base models are the same architecture”

Most current base models are decoder-only Transformers, but the details matter: attention variants (GQA, MLA), positional encodings (RoPE, ALiBi, absolute), tokenization strategies, data mixtures, training schedules, and compute budgets all produce meaningfully different models. A 7B base model trained on 2T tokens of high-quality data can outperform a 13B model trained on 1T tokens of noisier data. Parameter count is a poor proxy for capability.

Working with base models in practice

If you’re integrating a base model, three practical considerations:

Prompt formatting matters more. Without a chat template, you own the prompt engineering. Few-shot examples, explicit stopping sequences, and careful prefix design replace the alignment layer’s implicit behavior.

# Example: few-shot prompting a base model for JSON extraction
prompt = """Extract entities as JSON.

Text: "Apple announced the iPhone 15 on September 12, 2023."
JSON: {"company": "Apple", "product": "iPhone 15", "date": "2023-09-12"}

Text: "Microsoft acquired Activision Blizzard for $68.7 billion."
JSON: {"company": "Microsoft", "acquisition": "Activision Blizzard", "value": "$68.7 billion"}

Text: "Tesla delivered 484,507 vehicles in Q3 2024."
JSON:"""

completion = base_model.generate(prompt, stop_sequences=["\n\nText:"])
# Returns: {"company": "Tesla", "metric": "vehicles delivered", "value": "484,507", "period": "Q3 2024"}

Stopping criteria are critical. Base models don’t know when to stop answering. You must provide explicit stop sequences (\n\n, ###, </s>, or task-specific delimiters) or implement heuristic stopping (max tokens, repetition detection, EOS probability threshold).

Sampling parameters need tuning. Base models often benefit from lower temperature (0.2–0.5) and top-p (0.9) for factual tasks, but higher settings for creative generation. The aligned model’s “safe defaults” don’t apply — you’re closer to the raw logits.

When to choose a base model

Use a base model when:

  • Building code completion or infilling tools
  • Generating synthetic training data for downstream tasks
  • Prototyping prompt patterns before committing to alignment
  • Evaluating raw model capabilities without alignment interference
  • Implementing RAG where retrieved context should be continued, not answered

Use an instruct/chat model when:

  • Building user-facing conversational interfaces
  • You need reliable instruction following without few-shot examples
  • Safety guardrails are required out of the box
  • The task is naturally framed as question-answering or dialogue

The base model explained in one paragraph

A base model is the raw output of large-scale next-token prediction training — no instruction tuning, no preference optimization, no chat template. It completes text according to the statistical patterns of its training corpus. This makes it fundamentally a continuation engine, not an instruction follower. For engineers, base models matter because they’re the foundation all aligned models build on, they excel at completion-style tasks (code, infilling, synthetic data), and they reveal the true capabilities and biases of the pre-training pipeline. Working with them requires explicit prompt engineering, careful stopping criteria, and a mental model of completion rather than conversation.

Tagsbase-modelsllm-basicsmodel-training

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All foundation models: base vs instruct vs chat posts →