Gen AI — Evaluation
Why evaluate?
Ensure AI systems produce accurate, helpful, and safe outputs.
Evaluation metrics
| Metric | Measures |
|---|---|
| Accuracy | Correct answers |
| Relevance | Topic alignment |
| Coherence | Logical flow |
| Fluency | Language quality |
Automated evaluation
def evaluate_response(response, expected):
return {
"exact_match": response == expected,
"contains_answer": expected.lower() in response.lower(),
"length_ratio": len(response) / len(expected)
}
LLM as judge
def llm_judge(question, response):
prompt = f"""
Rate this response on a scale of 1-5:
Question: {question}
Response: {response}
Criteria: accuracy, completeness, clarity
Output: score and brief explanation
"""
return client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
Human evaluation
evaluation_criteria = {
"accuracy": "Is the information correct?",
"relevance": "Does it answer the question?",
"clarity": "Is it easy to understand?",
"completeness": "Is it thorough?"
}
Benchmark datasets
- MMLU: Multiple-choice knowledge
- HumanEval: Code generation
- TruthfulQA: Factual accuracy
- HellaSwag: Common sense reasoning
Mini Practice
- Evaluate a model response
- Build an LLM judge
- Create evaluation criteria
- Test with benchmark data
Up Next
Continue with Hallucinations - When AI is wrong.
Related Topics
Frequently Asked Questions about Evaluation
What is Evaluation in Gen AI?
Evaluation is a fundamental concept in Gen AI. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Evaluation?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Evaluation.
Why is Evaluation important in Gen AI?
Evaluation is essential for Gen AI development. Understanding this concept will help you write better code and solve real-world problems more effectively.