요약 점수(Summarization Score)
요약 점수(Summarization Score)
요약 점수는 요약(response)이 reference_contexts의 중요한 정보를 얼마나 잘 담아내는지 측정하는 지표예요. 좋은 요약은 컨텍스트에 있는 중요한 정보를 모두 포함해야 한다는 직관에서 출발해요. 요약이 단순히 원문을 복사해 높은 점수를 받는 일도 막아주죠.
출처: 문서
본문
요약 점수(Summarization Score)
Summarization Score 지표는 요약(response)이 reference_contexts의 중요한 정보를 얼마나 잘 담아내는지 측정해요. 이 지표의 직관은 좋은 요약이 컨텍스트에 있는 모든 중요한 정보를 포함해야 한다는 거예요.
먼저 컨텍스트에서 중요한 키프레이즈(keyphrases) 집합을 추출해요. 이 키프레이즈들은 질문 집합을 생성하는 데 사용돼요. 이 질문들에 대한 답변은 컨텍스트에 대해 항상 yes(1)이에요. 그런 다음 이 질문들을 요약에 물어보고, 올바르게 답변된 질문 수 대비 전체 질문 수의 비율로 요약 점수를 계산해요.
QA 점수를 답변(결과가 1과 0의 리스트)을 사용해 계산해요. QA 점수는 올바르게 답변된 질문(answer = 1) 수를 전체 질문 수로 나눈 비율로 계산돼요.
[ \text{QA score} = \frac{|\text{correctly answered questions}|}{|\text{total questions}|} ]
또한 간결성(conciseness) 점수를 제공해 더 큰 요약에 패널티를 주는 옵션도 있어요. 이 옵션이 활성화되면 최종 점수는 요약 점수와 간결성 점수의 가중 평균으로 계산돼요. 이 간결성 점수는 원문을 그대로 복사한 요약이 큰 점수를 받지 못하게 해줘요. 그런 요약은 당연히 모든 질문에 정확히 답할 테니까요.
[ \text{conciseness score} = 1 - \frac{\min(\text{length of summary}, \text{length of context})}{\text{length of context} + \text{1e-10}} ]
또한 점수의 가중치를 제어하는 계수 coeff(기본값 0.5)를 제공해요.
최종 요약 점수는 다음과 같이 계산돼요:
[ \text{Summarization Score} = \text{QA score}(1-\text{coeff}) + \text{conciseness score}\text{coeff} ]
예시(Example)
from openai import AsyncOpenAI
from ragas.llms import llm_factory
from ragas.metrics.collections import SummaryScore
# Setup LLM
client = AsyncOpenAI()
llm = llm_factory("gpt-4o-mini", client=client)
# Create metric
scorer = SummaryScore(llm=llm)
# Evaluate
result = await scorer.ascore(
reference_contexts=[
"A company is launching a new product, a smartphone app designed to help users track their fitness goals. The app allows users to set daily exercise targets, log their meals, and track their water intake. It also provides personalized workout recommendations and sends motivational reminders throughout the day."
],
response="A company is launching a fitness tracking app that helps users set exercise goals, log meals, and track water intake, with personalized workout suggestions and motivational reminders."
)
print(f"Summary Score: {result.value}")
출력(Output):
Summary Score: 0.6423387096775146
동기 사용법(Synchronous Usage) 동기 코드를 선호한다면
.ascore()대신.score()메서드를 쓸 수 있어요:result = scorer.score( reference_contexts=[...], response="..." )
레거시 지표 API(Legacy Metrics API)
다음 예시는 레거시 지표 API 패턴을 사용해요. 새 프로젝트에는 위에서 보여준 컬렉션 기반 API를 권장해요.
폐지 일정(Deprecation Timeline) 이 API는 버전 0.4에서 폐지되고 버전 1.0에서 제거될 예정이에요. 위에 보여준 컬렉션 기반 API로 마이그레이션해주세요.
SingleTurnSample과 함께하는 예시(Example with SingleTurnSample)
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics import SummarizationScore
sample = SingleTurnSample(
response="A company is launching a fitness tracking app that helps users set exercise goals, log meals, and track water intake, with personalized workout suggestions and motivational reminders.",
reference_contexts=[
"A company is launching a new product, a smartphone app designed to help users track their fitness goals. The app allows users to set daily exercise targets, log their meals, and track their water intake. It also provides personalized workout recommendations and sends motivational reminders throughout the day."
]
)
scorer = SummarizationScore(llm=evaluator_llm)
await scorer.single_turn_ascore(sample)
출력(Output):
0.6423387096775146