Language models, retrieval, prompting, and language adaptation · Instruction, preference, and parameter-efficient adaptation · LNG061 · Training method
FLAN instruction tuning
Fine-tunes language models on many tasks expressed as natural-language instructions to improve generalization to new task descriptions. It is a training approach;
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
Fine-tunes language models on many tasks expressed as natural-language instructions to improve generalization to new task descriptions. It is a training approach; later FLAN checkpoints and mixtures should not be counted as independent architectural principles.
Question / objective
Can supervised instruction mixtures improve transfer to task descriptions absent from training?
Architecture / computational structure
A pretrained model's architecture is unchanged; natural-language task formulations supply supervised targets. Learned updated weights/adapters are parameters; task sampling, templates, learning rates, and response masks are hyperparameters.
Assumptions
Claimed zero-shot transfer requires excluding evaluation tasks and related leakage from instruction training.
Formula / computational definition
Minimize sum_i -log p_theta(y_i|instruction_i,x_i) across task mixtures. Task templates and dataset sampling determine which behaviors receive gradient updates and how much weight each task contributes.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Task mixture, instruction templates, dataset weights, base model, optimization schedule, context budget, and held-out task definition.
Fitting, fine-tuning, and adaptation
Perform SFT with explicit instruction/input/response records, full updates or supported LoRA/adapters. Freeze base weights for parameter-efficient training, and reserve whole task families for validation. Mix representative general data if retention matters; evaluate instruction following, factuality, and catastrophic forgetting beyond training loss.
How to use and calibrate
Hold out whole tasks or task families, test paraphrased instructions, and track base capability retention, factuality, and task-format compliance. 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
Teach one model several workflow tasks while measuring transfer to a new instruction type.
Interpretation / pitfalls
Watch out
Supervised task labels mean instruction tuning is not unsupervised learning even when the base model used self-supervised pretraining. 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: Train with a documented supervised-fine-tuning loop using Transformers/TRL where appropriate; format encoder–decoder versus causal targets correctly. R bridges Python with reticulate. The native example computes a weighted task loss, not a complete instruction-tuned model.
Example scope: FLAN task-mixture supervised loss with explicit task weights.
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 — FLAN task-mixture supervised loss with explicit task weights.
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)
task_weights, task_losses = [0.5,0.3,0.2], [0.8,1.2,1.5]
print(dot(task_weights,task_losses))
Component demo, not a trained model — FLAN task-mixture supervised loss with explicit task weights.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
task_weights <- c(0.5,0.3,0.2); task_losses <- c(0.8,1.2,1.5)
print(sum(task_weights*task_losses))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG061.