Evaluating Fine-Tuned Models: Beyond Word Match

Evaluating Fine-Tuned Models: Beyond Word Match

Master the metrics of AI performance. Learn how to use Perplexity, ROUGE, and LLM-as-a-Judge to measure if your fine-tuning was a success or a hallucination-filled failure.

Evaluating Fine-Tuned Models: Beyond Word Match

The final step in the fine-tuning process is Validation. How do you know if your model is actually "smarter" than it was before? In traditional code, we have unit tests. In AI, performance is nuanced.

In this lesson, we will cover the metrics that matter and the "Gold Standard" of modern evaluation: LLM-as-a-Judge.


1. Traditional Metrics (The Math Side)

Perplexity (PPL)

Perplexity measures how "surprised" a model is by new data.

  • Low Perplexity: The model predicts the next word with high confidence. (Usually good).
  • High Perplexity: The model is confused.

ROUGE and BLEU

These metrics look at how many words in the model's output match the "Reference Answer."

  • Problem: In AI, you can say the same thing using different words. A model that says "The capital of France is Paris" is correct, but if the reference answer is "Paris is France's capital," traditional metrics might give it a low score!

2. LLM-as-a-Judge (The Industry Standard)

Because language is subjective, the best way to evaluate an LLM is to use a more powerful LLM to grade it.

The Elo Rating System

You take the original Base Model and your new Fine-tuned Model. You give them both the same 100 questions. You then show both answers to a neutral "Judge" (e.g., GPT-4o) and ask it to pick a winner.

graph TD
    A[Question] --> B[Base Model Output]
    A --> C[Fine-tuned Model Output]
    B --> D[Judge: GPT-4o]
    C --> D
    D --> E{Winner Selected}
    E --> F[Elo Score Update]

The "Rubric" Prompt:

To make the judge reliable, you give it a specific rubric: "You are an expert evaluator. Grade these two answers on a scale of 1 to 5 based on: Accuracy, Tone adherence, and Conciseness. If both are tied, explain why."


3. Benchmarking: MMLU and GSM8K

You should also run your model against public benchmarks to ensure you didn't break its "General Intelligence."

  • MMLU: Multiple-choice questions across 57 subjects (STEM, Humanities, etc.).
  • GSM8K: Grade-school math questions. If your fine-tuning on "Poetry" makes your math score drop from 60% to 10%, you have Catastrophic Forgetting.

4. Manual "Vibe Checks"

Never trust a leaderboard 100%. As an LLM Engineer, you must perform Blind A/B Testing.

  1. Set up a simple UI.
  2. Show two anonymous responses.
  3. Have your human team members (or subject matter experts) vote on which is better.

Code Concept: A Simple Judge Script

def evaluate_result(question, answer_a, answer_b):
    judge_prompt = f"""
    Compare these two AI responses to the question: '{question}'
    Response A: {answer_a}
    Response B: {answer_b}
    
    Which one is more professional and accurate? 
    Answer MUST be 'A' or 'B'.
    """
    judge_result = call_llm(judge_prompt, model="gpt-4o")
    return judge_result

# Usage
winner = evaluate_result("Explain photosynthesis", "It's how plants eat sunlight.", "It's the biochemical process by which plants convert CO2 and H2O into glucose.")
print(f"The winner is: {winner}")

Summary of Module 6

  • LoRA and PEFT allow you to specialize models cheaply (6.2).
  • Dataset Choice determines your model's soul; prioritize quality over quantity (6.3).
  • Evaluation is the only way to know if you're improving. Use LLM-as-a-Judge for nuance and Benchmarks for stability (6.4).

You now understand how to specialize a model's brain. In the next module, we move into the most exciting part of the course: LLM Agents and Orchestration, where we put these models in the driver's seat of autonomous systems.


Exercise: The Biased Judge

You use GPT-4o to judge your fine-tuned Llama 3 model. You notice that GPT-4o always picks the answer that is longer, even if it's less accurate. This is called Positional or Verbosity Bias.

How would you adjust your "Judge Prompt" to fix this?

Answer Logic:

  1. Explicitly instruct the judge: "A shorter, accurate answer is superior to a long, repetitive one."
  2. Rotate the order: Show the answers as (A,B) sometimes and (B,A) other times to ensure the judge isn't just picking the first option.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn