평가 샘플(Evaluation Sample)

평가 샘플(Evaluation Sample)

평가 샘플은 특정 시나리오에서 LLM 애플리케이션의 성능을 측정·평가하는 데 사용되는 단일 구조화 데이터 인스턴스예요. AI 애플리케이션이 처리해야 할 하나의 상호작용 단위 또는 특정 사용 사례를 나타내죠. Ragas에서는 SingleTurnSampleMultiTurnSample 클래스로 표현해요.

출처: 문서

본문

SingleTurnSample

SingleTurnSample은 사용자, LLM, 그리고 평가를 위한 기대 결과 사이의 단일 턴 상호작용을 나타내요. 추가 컨텍스트나 레퍼런스 정보가 있을 수 있는 단일 질문-답변 쌍을 다루는 평가에 적합해요.

예시(Example)

다음 예시는 RAG 기반 애플리케이션에서 단일 턴 상호작용을 평가하기 위한 SingleTurnSample 인스턴스를 만드는 방법을 보여줘요. 사용자가 질문하고 AI가 답변하는 시나리오예요. 검색된 컨텍스트, 레퍼런스 답변, 평가 루브릭을 포함해 이 상호작용을 나타내는 SingleTurnSample 인스턴스를 만들어볼게요.

from ragas import SingleTurnSample

# User's question
user_input = "What is the capital of France?"

# Retrieved contexts (e.g., from a knowledge base or search engine)
retrieved_contexts = ["Paris is the capital and most populous city of France."]

# AI's response
response = "The capital of France is Paris."

# Reference answer (ground truth)
reference = "Paris"

# Evaluation rubric
rubric = {
    "accuracy": "Correct",
    "completeness": "High",
    "fluency": "Excellent"
}

# Create the SingleTurnSample instance
sample = SingleTurnSample(
    user_input=user_input,
    retrieved_contexts=retrieved_contexts,
    response=response,
    reference=reference,
    rubric=rubric
)

MultiTurnSample

MultiTurnSample은 인간과 AI, 그리고 선택적으로 Tool 사이의 다중 턴 상호작용과 평가를 위한 기대 결과를 나타내요. 더 복잡한 상호작용에서 대화형 에이전트를 평가하는 데 적합해요. MultiTurnSample에서 user_input 속성은 인간 사용자와 AI 시스템 사이의 다중 턴 대화를 함께 이루는 메시지 시퀀스를 나타내요. 이 메시지는 HumanMessage, AIMessage, ToolMessage 클래스의 인스턴스예요.

예시(Example)

다음 예시는 다중 턴 상호작용을 평가하기 위한 MultiTurnSample 인스턴스를 만드는 방법을 보여줘요. 사용자가 뉴욕의 현재 날씨를 알고 싶어 하는 시나리오예요. AI 어시스턴트가 날씨 API 도구를 사용해 정보를 가져와 사용자에게 응답해요.

from ragas.messages import HumanMessage, AIMessage, ToolMessage, ToolCall

# User asks about the weather in New York City
user_message = HumanMessage(content="What's the weather like in New York City today?")

# AI decides to use a weather API tool to fetch the information
ai_initial_response = AIMessage(
    content="Let me check the current weather in New York City for you.",
    tool_calls=[ToolCall(name="WeatherAPI", args={"location": "New York City"})]
)

# Tool provides the weather information
tool_response = ToolMessage(content="It's sunny with a temperature of 75°F in New York City.")

# AI delivers the final response to the user
ai_final_response = AIMessage(content="It's sunny and 75 degrees Fahrenheit in New York City today.")

# Combine all messages into a list to represent the conversation
conversation = [
    user_message,
    ai_initial_response,
    tool_response,
    ai_final_response
]

이제 conversation을 사용해 MultiTurnSample 객체를 만들고, 레퍼런스 응답과 평가 루브릭을 포함해요.

from ragas import MultiTurnSample
# Reference response for evaluation purposes
reference_response = "Provide the current weather in New York City to the user."

# Create the MultiTurnSample instance
sample = MultiTurnSample(
    user_input=conversation,
    reference=reference_response,
)

더 알아보기 (Learn more)