프롬프트 평가 퀵스타트
프롬프트 평가 퀵스타트 (Prompt Evaluation Quickstart)
prompt_evals 템플릿은 감정 분석으로 다양한 프롬프트 변형을 평가하고 비교해요. 프로젝트 생성부터 프롬프트 버전별 정확도 비교까지 진행할 수 있어요.
출처: 문서
본문
prompt_evals 템플릿은 감정 분석과 함께 다양한 프롬프트 변형을 평가하고 비교해요.
프로젝트 만들기
ragas quickstart prompt_evals
cd prompt_evals
의존성 설치
uv sync
API 키 설정
export OPENAI_API_KEY="your-openai-key"
평가 실행
uv run python evals.py
프로젝트 구조
prompt_evals/
├── README.md # Project documentation
├── pyproject.toml # Project configuration
├── prompt.py # Prompt implementation
├── evals.py # Evaluation workflow
├── __init__.py # Python package marker
└── evals/
├── datasets/ # Test datasets
├── experiments/ # Evaluation results
└── logs/ # Execution logs
무엇을 평가하나
템플릿은 감정 분류에서 프롬프트 효과를 평가해요.
- Task: 감정 분석 (positive/negative)
- Test Cases: 기대 감정 라벨이 있는 영화 리뷰
- Metric: 이진 정확도 (pass/fail)
코드 이해하기
프롬프트 (prompt.py)
감정 분석 프롬프트를 구현해요.
from prompt import run_prompt
sentiment = run_prompt("I loved the movie! It was fantastic.")
# Returns: "positive" or "negative"
평가 (evals.py)
프롬프트 정확도를 테스트해요.
@discrete_metric(name="accuracy", allowed_values=["pass", "fail"])
def my_metric(prediction: str, actual: str):
return (
MetricResult(value="pass", reason="")
if prediction == actual
else MetricResult(value="fail", reason="")
)
테스트 데이터
데이터셋은 영화 리뷰를 포함해요.
dataset_dict = [
{"text": "I loved the movie! It was fantastic.", "label": "positive"},
{"text": "The movie was terrible and boring.", "label": "negative"},
# More examples...
]
커스터마이즈
다른 프롬프트 테스트
변형을 테스트하려면 prompt.py를 수정해요.
# Version 1: Simple
prompt = f"Is this positive or negative: {text}"
# Version 2: With examples
prompt = f"""Classify sentiment:
Examples:
- "Great movie" -> positive
- "Boring film" -> negative
Text: {text}
Sentiment:"""
# 버전별 결과 비교
메트릭 추가
추가 측면을 평가해요.
from ragas.metrics import NumericalMetric
confidence = NumericalMetric(
name="confidence",
prompt="Rate confidence 1-5 in this classification: {prediction}",
allowed_values=(1, 5),
)
더 알아보기 (Learn more)
- Judge Alignment - LLM-as-judge 정렬 측정
- LLM Benchmarking - 다양한 모델 비교