Skip to content

Language models, retrieval, prompting, and language adaptation · Instruction, preference, and parameter-efficient adaptation · LNG064 · Training method

Constitutional AI

Uses written principles to guide model critique, revision, and AI-generated preference feedback. The approach changes how supervision is produced;

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

Uses written principles to guide model critique, revision, and AI-generated preference feedback. The approach changes how supervision is produced; it does not eliminate human choices about principles, data, or evaluation.

Question / objective

Can principle-conditioned automated critique supply useful supervision for policy improvement?

Architecture / computational structure

A feedback model generates critiques/revisions/preferences from written principles; a policy then learns from those outputs. Learned policy/reward components are distinct from the selected principles, prompts, and teacher configuration.

Assumptions

Principles can conflict or be underspecified, and feedback models may share the policy's blind spots.

Formula / computational definition

y~=Revise⁡(y,Critique⁡(x,y,C)),Lrevision=−log⁡pθ(y~∣x).\widetilde y=\operatorname{Revise}(y,\operatorname{Critique}(x,y,C)),\qquad \mathcal L_{\mathrm{revision}}=-\log p_\theta(\widetilde y\mid x).

A supervised stage learns from principle-guided revised responses; a preference stage trains a reward or policy objective from AI-ranked pairs. Pairwise logistic preference losses can be used, but the defining feature is the principle-conditioned feedback pipeline.

Parameters and notation

Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Principle set, critique/revision prompts, teacher model, sampling strategy, preference aggregation, policy regularization, and review procedures.

Fitting, fine-tuning, and adaptation

Create reviewed critique/revision data, SFT the policy, and apply the stated preference stage. Freeze a feedback model for reproducibility; use supported policy adapters or full updates. Validate with independent humans and factuality tests, since the feedback model can share errors; monitor capability retention and principle conflicts.

How to use and calibrate

Assess principle adherence, helpfulness, factuality, edge cases, and human disagreement; compare automated judgments with independently collected human evaluations. 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

Train responses to follow explicit organizational communication principles while auditing disagreements.

Interpretation / pitfalls

Watch out

Self-consistent agreement is not independent evidence of truth or harmlessness. 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: Implement the documented critique/revision and preference-data pipeline around a supported language model, then use appropriate SFT/preference tooling. R can orchestrate through reticulate. The native example aggregates principle scores solely as an illustration; it is not a universal Constitutional AI scoring formula.

Example scope: Illustrative principle-score aggregation for automated feedback; not a universal Constitutional AI objective.

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 — Illustrative principle-score aggregation for automated feedback; not a universal Constitutional AI objective.

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)
principle_weights = [0.5,0.3,0.2]
response_scores = [[0.9,0.8,0.7],[0.6,0.9,0.9]]
ratings = [dot(principle_weights,s) for s in response_scores]
print(ratings)
R

Component demo, not a trained model — Illustrative principle-score aggregation for automated feedback; not a universal Constitutional AI objective.

Shared setup for this chapter
softmax <- function(x) {
  shifted <- exp(x-max(x))
  shifted/sum(shifted)
}
principle_weights <- c(0.5,0.3,0.2)
response_scores <- rbind(c(0.9,0.8,0.7),c(0.6,0.9,0.9))
ratings <- drop(response_scores %*% principle_weights)
print(ratings)

Sources

From the CodeSplash reference, entry LNG064.