simpo-loss-function

An implementation guide for SimPO, a training method that teaches a language model to rank a preferred response above a less preferred one. It scores responses using their average token log probability and a target gap between them.

In plain words
What is it for?
Use it when implementing preference training for language models with pairs of winning and losing responses.
Why use it?
It helps compare responses without favouring longer or shorter text simply because of its length, while enforcing a clear score difference between preferred and rejected answers.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/cxcscmu/skilllearnbench/simpo-loss-function
Any agent
npx skills add cxcscmu/SkillLearnBench --skill simpo-loss-function
Clone the repo
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench

Made for: Claude Code, Codex.

Per session 18 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 724 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00018 $0.00724
Opus 5 $0.00009 $0.00362
Sonnet 5 $0.00004 $0.00145
Haiku 4.5 $0.00002 $0.00072

Measured 2d ago against content hash dd61897e5dbb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

simpo-loss-function scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/b1-one-shot-claude-haiku-4-5/nlp-paper-reproduction/simpo-loss-function/SKILL.md · 83 lines

How it starts

The opening of the file, as written. The whole thing — 83 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SimPO Loss Function Implementation

Overview

SimPO (Simple Preference Optimization) implements a preference optimization objective that uses length-normalized average log probability as an implicit reward, with a target reward margin component.

Key Formula

L_SimPO(πθ) = -E_(x,yw,yl)~D log σ(β/|yw| log πθ(yw|x) - β/|yl| log πθ(yl|x) - γ)

Components

1. Length-Normalized Reward

  • Formula: r_SimPO(x, y) = β/|y| * log πθ(y|x)
  • Purpose: Average log probability per token, prevents length bias
  • Why: Aligns training with generation metric (which uses average log likelihood for beam search)

2. Bradley-Terry Objective

  • Formula: p(yw ≻ yl | x) = σ(r(x, yw) - r(x, yl) - γ)
  • Purpose: Probabilistic ranking between winning and losing responses
  • Function: σ is sigmoid function

3. Target Reward Margin (γ)

  • Purpose: Ensure reward difference exceeds a target threshold
  • Effect: Improves generalization by enforcing margin between classes
  • Typical range: 0.5 to 1.5

Implementation Details

Computing Log Probabilities

# log_probs shape: (batch_size, seq_len)
# Sum across sequence dimension to get total log probability
log_prob_sum = log_probs.sum(dim=1)  # (batch_size,)

# Divide by sequence length for normalization
seq_lengths = (input_ids != pad_token_id).sum(dim=1)  # (batch_size,)
avg_log_prob = log_prob_sum / seq_lengths.float()  # (batch_size,)

Computing Reward Differences

# Batch structure: pairs of (winning, losing) responses
batch_size = avg_log_probs.shape[0]
winning_rewards = avg_log_probs[:batch_size//2]
losing_rewards = avg_log_probs[batch_size//2:]

# Reward difference with margin
reward_diff = beta * winning_rewards - beta * losing_rewards - gamma

Computing Loss

# Bradley-Terry with sigmoid
import torch.nn.functional as F

sigmoid_term = torch.sigmoid(reward_diff)
loss = -torch.log(sigmoid_term).mean()

Common Pitfalls

  1. Not using length normalization: Creates bias toward longer sequences
  2. Wrong batch structure: Ensure paired winning/losing responses
  3. Missing average in log probabilities: Use sum/length, not just sum
  4. Gradient flow: Ensure no detach() breaks gradients to model

Read the full file on GitHub · 83 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 83 lines · 18 tokens per session scan A dd61897e5dbb

Subscribe to this mod's changes

simpo-loss-function is a skill published in the GitHub repository cxcscmu/SkillLearnBench (82 stars, last pushed 1mo ago), licensed MIT. It adds 18 tokens to every session and 724 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

generating-mod-envs

Generates and reviews mod learning env JSON files for Letta Code local mods. Use when asked to teach, learn, or optimize a mod behavior; create, draft, validate, improve, or explain envs for /mods learn --env; or design evaluation scenarios, memory fixtures, requiredResultMarkers, requiredTraceMarkers, negative…

letta-ai/letta-code · 79 tokens

agentsop-signature-design

Decision rubric for promoting a prose prompt into a typed DSPy Signature. This is an ENHANCE overlay on top of the [[dspy]] library skill: it does NOT teach DSPy syntax — it answers the coder-agent decision "when do I stop hand-writing a prompt string and declare it as a dspy.Signature, and how do I name/describe its…

agentsope/SkillAlchemy · 226 tokens

speech-to-text

Transcribe video to timestamped text using Whisper tiny model (pre-installed).

benchflow-ai/skillsbench · 19 tokens

aspirations-spark

Runs the Spark Check (Phase 6) and Immediate Learning (Phase 6.5) of the aspirations loop: adaptive spark questions, all sq-XXX handlers (including sq-012 self-purpose update), aspiration-level spark, and immediate capture of reasoning-bank entries, guardrails, and forge awareness. Use whenever a goal completes — this…

zkysar1/Claude-Mind · 104 tokens

respond

Handles every user message in assistant and autonomous modes: activates persona, runs mandatory 3-tier retrieval escalation (tree → codebase → web), detects and routes user directives (new aspirations, corrections, preferences), performs knowledge-freshness reconciliation, and captures interaction-level learning into…

zkysar1/Claude-Mind · 92 tokens

start

Creates or resumes an agent in reader (read-only), assistant (user-directed), or autonomous mode (perpetual loop), handling full initialization for new agents (Self, program, paths, aspirations, curriculum) and state transitions for existing ones. USER-ONLY — Claude must NEVER invoke /start. Fires only when the user…

zkysar1/Claude-Mind · 141 tokens