Skip to content

Add behavioral_drift: fine-tuning output integrity metric beyond loss curves#778

Open
YuhaoLin2005 wants to merge 1 commit into
huggingface:mainfrom
YuhaoLin2005:add-behavioral-drift
Open

Add behavioral_drift: fine-tuning output integrity metric beyond loss curves#778
YuhaoLin2005 wants to merge 1 commit into
huggingface:mainfrom
YuhaoLin2005:add-behavioral-drift

Conversation

@YuhaoLin2005

Copy link
Copy Markdown

What problem does this solve?

Loss curves improve during fine-tuning and everyone ships. But loss can drop while every output degenerates into repeating digit sequences or near-identical strings. Perplexity does not catch this — it measures token-level prediction quality, not output integrity. BLEU/ROUGE do not catch this either — they measure n-gram overlap against ground truth, not behavioral collapse against a baseline.

There is currently no metric in evaluate that catches this class of failure.

How it works

behavioral_drift composites three signals into a single drift_score (0-1, lower = worse):

  1. self-BLEU — concatenated-reference BLEU-1 across fine-tuned outputs. High self-BLEU means the model is producing near-identical strings regardless of input (mode collapse).
  2. digit density delta — compares the fraction of numeric characters in fine-tuned outputs vs. base model outputs. A sudden spike means the model is producing numeric garbage instead of language.
  3. repetition ratio — unique-token / total-token ratio per output. Low ratio means degenerate token looping.

Each signal has a documented threshold. A diagnosis string is returned alongside the score.

Relationship to existing metrics

Not a replacement for perplexity or BLEU. An orthogonal behavioral check. Intended workflow: run drift_score alongside your standard eval suite. If perplexity improves but drift_score drops, you have a silent quality regression.

Implementation

  • 147 lines of Python, single file
  • Zero external dependencies beyond evaluate + datasets
  • Pure deterministic computation — no model calls, no stochastic components
  • Demo app (app.py) included for interactive testing via Gradio

Three-signal composite (self-BLEU, digit density, repetition ratio) that catches fine-tuning collapse invisible to perplexity alone. 147 lines, zero external dependencies beyond evaluate+datasets.
@YuhaoLin2005

Copy link
Copy Markdown
Author

Real-world failure case this metric catches

During a 6-round Qwen2.5-1.5B fine-tuning experiment, I observed:

Round Loss Actual Behavior
3 9.13 Normal output
4 8.78 (improved!) Output collapsed to repeating digit sequences

Loss improved. The model broke. No standard metric caught it.

This is the exact failure mode behavioral_drift detects:

  • self-BLEU spikes (near-identical outputs regardless of input)
  • digit_density_delta spikes (numeric garbage replacing language)
  • repetition_ratio drops (degenerate token looping)

The multiplicative formula scores this case as 0.0 (total collapse). An additive alternative gives 0.67 (misleadingly high).

Experiment details and metric design rationale available in the repo: github.com/YuhaoLin2005/training-gate

Happy to add more test cases or adjust threshold defaults per maintainer preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant