Persona 생성

Persona 생성

테스트셋 생성 과정에 다양한 persona(사용자 유형)를 추가할 수 있어요. Persona 클래스를 name과 role description으로 정의하면, 사용 사례에 맞는 persona별 테스트셋을 만들 수 있어요.

출처: 문서

본문

테스트셋 생성에서의 Persona

[Persona][ragas.testset.persona.Persona] 클래스를 name과 role description으로 정의해서 테스트셋 생성 과정에 여러 persona를 추가할 수 있어요. 이것은 사용 사례에 관련 있는 다양한 persona를 설정하고 그에 맞는 테스트셋을 생성하기 위함이에요.

예를 들어 GitLab handbook에 대해 신입사원(new joinee), 매니저(manager), 시니어 매니저(senior manager) 같은 여러 persona별 테스트셋을 만들고 싶을 수 있어요. 그래서 다음과 같이 정의할 거예요.

  • New Joinee: 회사에 대해 잘 모르고 어떻게 시작하는지 정보를 찾고 있어요.
  • Manager: 다양한 팀과 팀들이 서로 어떻게 협업하는지 알고 싶어 해요.
  • Senior Manager: 회사 비전과 그것이 어떻게 실행되는지 알고 싶어 해요.

다음과 같이 정의할 수 있어요.

from ragas.testset.persona import Persona

persona_new_joinee = Persona(
    name="New Joinee",
    role_description="Don't know much about the company and is looking for information on how to get started.",
)
persona_manager = Persona(
    name="Manager",
    role_description="Wants to know about the different teams and how they collaborate with each other.",
)
persona_senior_manager = Persona(
    name="Senior Manager",
    role_description="Wants to know about the company vision and how it is executed.",
)

personas = [persona_new_joinee, persona_manager, persona_senior_manager]
personas
[Persona(name='New Joinee', role_description="Don't know much about the company and is looking for information on how to get started."),
 Persona(name='Manager', role_description='Wants to know about the different teams and how they collaborate with each other.'),
 Persona(name='Senior Manager', role_description='Wants to know about the company vision and how it is executed.')]

그리고 이 persona들을 [TestsetGenerator][ragas.testset.generator.TestsetGenerator] 클래스에 전달해서 테스트셋 생성 과정에서 사용할 수 있어요.

from openai import OpenAI
from ragas.testset import TestsetGenerator
from ragas.testset.graph import KnowledgeGraph
from ragas.llms import llm_factory

# Load the knowledge graph
kg = KnowledgeGraph.load("../../../../experiments/gitlab_kg.json")
# Initialize the Generator LLM
openai_client = OpenAI()
llm = llm_factory("gpt-4o-mini", client=openai_client)

# Initialize the Testset Generator
testset_generator = TestsetGenerator(knowledge_graph=kg, persona_list=personas, llm=llm)
# Generate the Testset
testset = testset_generator.generate(testset_size=10)
testset
testset.to_pandas().head()

자동 Persona 생성

지식 그래프(knowledge graph)에서 persona를 자동으로 생성하고 싶다면 [generate_personas_from_kg][ragas.testset.persona.generate_personas_from_kg] 함수를 사용할 수 있어요.

from ragas.testset.persona import generate_personas_from_kg
from ragas.testset.graph import KnowledgeGraph
from ragas.llms import llm_factory

kg = KnowledgeGraph.load("../../../../experiments/gitlab_kg.json")
llm = llm_factory("gpt-4o-mini")

personas = generate_personas_from_kg(kg=kg, llm=llm, num_personas=5)

personas
[Persona(name='Organizational Development Manager', role_description='Responsible for implementing job frameworks and career development strategies to enhance employee growth and clarify roles within the company.'),
 Persona(name='DevSecOps Product Manager', role_description='Responsible for overseeing the development and strategy of DevSecOps solutions, ensuring alignment with company goals and user needs.'),
 Persona(name='Product Pricing Analyst', role_description='Responsible for developing and analyzing pricing strategies that align with customer needs and market demands.'),
 Persona(name='Site Reliability Engineer', role_description='Responsible for maintaining service reliability and performance, focusing on implementing rate limits to prevent outages and enhance system stability.'),
 Persona(name='Security Operations Engineer', role_description="Works on enhancing security logging processes and ensuring compliance within GitLab's infrastructure.")]

더 알아보기 (Learn more)