Skip to content

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

Phi model family

Documents relatively compact language-model systems emphasizing carefully constructed training data, with the Phi-4 report discussing synthetic-data contributions.

Explained here Component demo, not a trained model CodeSplash's own run

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

Documents relatively compact language-model systems emphasizing carefully constructed training data, with the Phi-4 report discussing synthetic-data contributions. The family highlights data design as a major modeling choice rather than treating parameter count as the only determinant of capability.

Question / objective

How much capability can a compact decoder gain from carefully constructed training examples?

Architecture / computational structure

A causal language model learns token representations and decoder weights from curated mixtures. Learned tensors are distinct from data-source proportions, synthetic-example filters, and evaluation prompts, which are design choices.

Assumptions

Synthetic examples may inherit teacher errors or narrow stylistic patterns.

Formula / computational definition

L(θ)=∑jπj Ex∼Dj[−log⁡pθ(x)],∑jπj=1.\mathcal L(\theta)=\sum_j\pi_j\,\mathbb E_{x\sim D_j}\left[-\log p_\theta(x)\right],\qquad \sum_j\pi_j=1.

Autoregressive cross-entropy is optimized over a mixture of data sources; if source j has weight pi_j, the population objective is sum_j pi_j E_Dj[-log p_theta(x)]. Synthetic-data generation and filtering shape those source distributions.

Parameters and notation

Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Exact release, data mixture, filtering and verification criteria, context length, tokenizer, adaptation recipe, and inference precision.

Fitting, fine-tuning, and adaptation

Continue training or instruction-tune on verified domain examples with supported LoRA/adapters or careful full updates. Audit synthetic answers and avoid teacher/evaluation leakage. Tune on independent tasks and monitor broad factuality and reasoning retention, since narrow synthetic curricula can over-specialize the model.

How to use and calibrate

Examine held-out reasoning, factuality, out-of-distribution tasks, contamination checks, and quality per unit memory or latency. 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

Adapt a compact model to verified technical exercises under a limited inference budget.

Interpretation / pitfalls

Watch out

Strong performance on curated reasoning tasks does not imply equally strong factual coverage or domain transfer. 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: Supported Phi checkpoints run through documented Transformers model classes; R uses reticulate. The example computes a weighted training loss to illustrate data-mixture effects, not the undisclosed complete training corpus.

Example scope: Data-mixture weighted language-model loss; relevant to curated Phi training, not an asserted recipe.

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 — Data-mixture weighted language-model loss; relevant to curated Phi training, not an asserted recipe.

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)
mixture, domain_losses = [0.5,0.3,0.2], [1.0,1.4,1.8]
print(dot(mixture,domain_losses))
R

Component demo, not a trained model — Data-mixture weighted language-model loss; relevant to curated Phi training, not an asserted recipe.

Shared setup for this chapter
softmax <- function(x) {
  shifted <- exp(x-max(x))
  shifted/sum(shifted)
}
mixture <- c(0.5,0.3,0.2); domain_losses <- c(1.0,1.4,1.8)
print(sum(mixture*domain_losses))

Sources

From the CodeSplash reference, entry LNG042.