hung-phan/ml-skills/metrics-and-feedback

Claude Code and agent skill by hung-phan/ml-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

DSPy metric design patterns — F1, semantic similarity, LLM-as-judge, and GEPA feedback. Use when writing metrics for DSPy optimization, choosing between metric types, or designing feedback for GEPA's reflection loop.

Install

npx vskill@latest install hung-phan/ml-skills/metrics-and-feedback

SKILL.md

The same SKILL.md was published earlier as hung-phan/ml-skills/metrics-and-feedback.

Metrics and Feedback

Why This Exists

Problem: The DSPy optimizer needs a differentiable signal — a function that returns a score (0–1) for each (input, output) pair. Bad metrics produce useless optimizations: binary metrics give GEPA nothing to reflect on, opaque scalar metrics give MIPROv2 a flat landscape to search, and expensive metrics make compilation unaffordable.

Key insight: The metric is the optimization target — its shape (bool vs float vs Prediction with feedback) determines which optimizer you can use and how well it converges.

Reach for this when: You need to write or choose a DSPy metric, design feedback for GEPA's reflection loop, or debug why an optimizer is plateauing or producing nonsensical results.

Metric Contract

python
def metric(example, pred, trace=None) -> bool | float | dspy.Prediction
Return TypeUsed ByBehavior
boolBootstrapFewShotPass/fail filtering
floatMIPROv2, BetterTogetherBayesian optimization signal
Prediction(score, feedback)GEPAReflection LM reads feedback

Built-in Metrics

MetricReturnsUse
answer_exact_matchboolFactoid QA
answer_passage_matchboolPassage contains gold
SemanticF1PredictionToken overlap + semantic
CompleteAndGroundedPredictionRAG completeness + groundedness

Token F1

python
def token_f1(prediction: str, reference: str) -> float:
pred_tokens = normalize(prediction).split()
ref_tokens = normalize(reference).split()
common = set(pred_tokens) & set(ref_tokens)
if not common: return 0.0
p = len(common) / len(pred_tokens)
r = len(common) / len(ref_tokens)
return 2 * p * r / (p + r)

Set F1 (multi-label, entity extraction)

python
def set_f1(predicted: set, gold: set) -> float:
if not predicted and not gold: return 1.0
if not predicted or not gold: return 0.0
p = len(predicted & gold) / len(predicted)
r = len(predicted & gold) / len(gold)
return 2 * p * r / (p + r) if (p + r) else 0.0

GEPA Metrics

GEPA reads feedback verbatim in its reflection prompt. This is the primary lever.

python
def gepa_metric(example, pred, trace=None, pred_name=None, pred_trace=None):
issues = []
scores = []
accuracy = check_facts(pred.response, example.response)
scores.append(accuracy)
if accuracy < 1.0:
issues.append(f"Accuracy {accuracy:.0%}: missing/wrong claims")
completeness = check_coverage(pred.response, example.response)
scores.append(completeness)
if completeness < 0.8:
issues.append(f"Covers only {completeness:.0%} of required points")
score = sum(scores) / len(scores)
feedback = "; ".join(issues) if issues else "Perfect."
return dspy.Prediction(score=score, feedback=feedback)
Good vs Bad GEPA Feedback
✅ Good❌ Bad
"Missing fact: user's timezone not included""Needs improvement"
"Format wrong: expected bullet list, got paragraph""Low score"
Fine-grained float (0.73)Binary (True/False)
Per-criterion breakdownSingle opaque number

GEPA vs MIPROv2

PropertyGEPAMIPROv2
Return typePrediction(score, feedback)float sufficient
FeedbackCritical — drives mutationsNot used
GranularityFine-grained requiredCoarse OK
pred_name/pred_traceUsed for per-predictor scoringNot used

Composite Pattern

python
def composite(example, pred, trace=None):
scores = {
"accuracy": check_accuracy(example, pred),
"format": float(check_format(pred)),
"concise": check_conciseness(pred),
}
weights = {"accuracy": 0.6, "format": 0.2, "concise": 0.2}
score = sum(w * scores[k] for k, w in weights.items())
issues = [f"{k}: {v:.2f}" for k, v in scores.items() if v < 0.8]
feedback = f"Weak: {', '.join(issues)}" if issues else "All met."
return dspy.Prediction(score=score, feedback=feedback)

Pitfalls

  • Plateau: All candidates score 0.85-0.90 → add more fine-grained criteria
  • Doesn't correlate: Validate metric vs human judgment on 20+ examples first
  • Too expensive: Use cheap LMs for scoring, cache repeated comparisons
  • Binary + GEPA: Reflection LM gets nothing to reflect on → always return float + feedback

References

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/hung-phan/ml-skills/metrics-and-feedback/badge)](https://verified-skill.com/skills/hung-phan/ml-skills/metrics-and-feedback)

Something wrong with this skill or its page? Tell us.