|
| 1 | +## Persona's in Testset Generation |
| 2 | + |
| 3 | +You can add different persona's to the testset generation process by defining the [Persona][ragas.testset.persona.Persona] class with the name and role description of the different persona's that might be relevant to your use case and you want to generate testset for. |
| 4 | + |
| 5 | +For example, for the [gitlab handbook](https://about.gitlab.com/handbook/) we might want to generate testset for different persona's like a new joinee, a manager, a senior manager, etc. And hence we will define them as follows: |
| 6 | + |
| 7 | +1. New Joinee: Don't know much about the company and is looking for information on how to get started. |
| 8 | +2. Manager: Wants to know about the different teams and how they collaborate with each other. |
| 9 | +3. Senior Manager: Wants to know about the company vision and how it is executed. |
| 10 | + |
| 11 | +Which we can define as follows: |
| 12 | + |
| 13 | + |
| 14 | +```python |
| 15 | +from ragas.testset.persona import Persona |
| 16 | + |
| 17 | +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.") |
| 18 | +persona_manager = Persona(name="Manager", role_description="Wants to know about the different teams and how they collaborate with each other.") |
| 19 | +persona_senior_manager = Persona(name="Senior Manager", role_description="Wants to know about the company vision and how it is executed.") |
| 20 | + |
| 21 | +personas = [persona_new_joinee, persona_manager, persona_senior_manager] |
| 22 | +personas |
| 23 | +``` |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + [Persona(name='New Joinee', role_description="Don't know much about the company and is looking for information on how to get started."), |
| 29 | + Persona(name='Manager', role_description='Wants to know about the different teams and how they collaborate with each other.'), |
| 30 | + Persona(name='Senior Manager', role_description='Wants to know about the company vision and how it is executed.')] |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +And then you can use these persona's in the testset generation process by passing them to the [TestsetGenerator][ragas.testset.generator.TestsetGenerator] class. |
| 35 | + |
| 36 | + |
| 37 | +```python |
| 38 | +from ragas.testset import TestsetGenerator |
| 39 | +from ragas.testset.graph import KnowledgeGraph |
| 40 | +from ragas.llms import llm_factory |
| 41 | + |
| 42 | +# Load the knowledge graph |
| 43 | +kg = KnowledgeGraph.load("../../../../experiments/gitlab_kg.json") |
| 44 | +# Initialize the Generator LLM |
| 45 | +llm = llm_factory("gpt-4o-mini") |
| 46 | + |
| 47 | +# Initialize the Testset Generator |
| 48 | +testset_generator = TestsetGenerator(knowledge_graph=kg, persona_list=personas, llm=llm) |
| 49 | +# Generate the Testset |
| 50 | +testset = testset_generator.generate(testset_size=10) |
| 51 | +testset |
| 52 | + |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | +```python |
| 57 | +testset.to_pandas().head() |
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +<div> |
| 64 | +<style scoped> |
| 65 | + .dataframe tbody tr th:only-of-type { |
| 66 | + vertical-align: middle; |
| 67 | + } |
| 68 | + |
| 69 | + .dataframe tbody tr th { |
| 70 | + vertical-align: top; |
| 71 | + } |
| 72 | + |
| 73 | + .dataframe thead th { |
| 74 | + text-align: right; |
| 75 | + } |
| 76 | +</style> |
| 77 | +<table border="1" class="dataframe"> |
| 78 | + <thead> |
| 79 | + <tr style="text-align: right;"> |
| 80 | + <th></th> |
| 81 | + <th>user_input</th> |
| 82 | + <th>reference_contexts</th> |
| 83 | + <th>reference</th> |
| 84 | + <th>synthesizer_name</th> |
| 85 | + </tr> |
| 86 | + </thead> |
| 87 | + <tbody> |
| 88 | + <tr> |
| 89 | + <th>0</th> |
| 90 | + <td>What the Director do in GitLab and how they wo...</td> |
| 91 | + <td>[09db4f3e-1c10-4863-9024-f869af48d3e0\n\ntitle...</td> |
| 92 | + <td>The Director at GitLab, such as the Director o...</td> |
| 93 | + <td>single_hop_specifc_query_synthesizer</td> |
| 94 | + </tr> |
| 95 | + <tr> |
| 96 | + <th>1</th> |
| 97 | + <td>Wht is the rol of the VP in GitLab?</td> |
| 98 | + <td>[56c84f1b-3558-4c80-b8a9-348e69a4801b\n\nJob F...</td> |
| 99 | + <td>The VP, or Vice President, at GitLab is respon...</td> |
| 100 | + <td>single_hop_specifc_query_synthesizer</td> |
| 101 | + </tr> |
| 102 | + <tr> |
| 103 | + <th>2</th> |
| 104 | + <td>What GitLab do for career progression?</td> |
| 105 | + <td>[ead619a5-930f-4e2b-b797-41927a04d2e3\n\nGoals...</td> |
| 106 | + <td>The Job frameworks at GitLab help team members...</td> |
| 107 | + <td>single_hop_specifc_query_synthesizer</td> |
| 108 | + </tr> |
| 109 | + <tr> |
| 110 | + <th>3</th> |
| 111 | + <td>Wht is the S-grop and how do they work with ot...</td> |
| 112 | + <td>[42babb12-b033-493f-b684-914e2b1b1d0f\n\nPeopl...</td> |
| 113 | + <td>Members of the S-group are expected to demonst...</td> |
| 114 | + <td>single_hop_specifc_query_synthesizer</td> |
| 115 | + </tr> |
| 116 | + <tr> |
| 117 | + <th>4</th> |
| 118 | + <td>How does Google execute its company vision?</td> |
| 119 | + <td>[c3ed463d-1cdc-4ba4-a6ca-2c4ab12da883\n\nof mo...</td> |
| 120 | + <td>To effectively execute the company vision, man...</td> |
| 121 | + <td>single_hop_specifc_query_synthesizer</td> |
| 122 | + </tr> |
| 123 | + </tbody> |
| 124 | +</table> |
| 125 | +</div> |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +## Automatic Persona Generation |
| 130 | + |
| 131 | +If you want to automatically generate persona's from a knowledge graph, you can use the [generate_personas_from_kg][ragas.testset.persona.generate_personas_from_kg] function. |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +```python |
| 136 | +from ragas.testset.persona import generate_personas_from_kg |
| 137 | +from ragas.testset.graph import KnowledgeGraph |
| 138 | +from ragas.llms import llm_factory |
| 139 | + |
| 140 | +kg = KnowledgeGraph.load("../../../../experiments/gitlab_kg.json") |
| 141 | +llm = llm_factory("gpt-4o-mini") |
| 142 | + |
| 143 | +personas = generate_personas_from_kg(kg=kg, llm=llm, num_personas=5) |
| 144 | +``` |
| 145 | + |
| 146 | + |
| 147 | +```python |
| 148 | +personas |
| 149 | +``` |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + [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.'), |
| 155 | + 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.'), |
| 156 | + Persona(name='Product Pricing Analyst', role_description='Responsible for developing and analyzing pricing strategies that align with customer needs and market demands.'), |
| 157 | + 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.'), |
| 158 | + Persona(name='Security Operations Engineer', role_description="Works on enhancing security logging processes and ensuring compliance within GitLab's infrastructure.")] |
| 159 | + |
| 160 | + |
0 commit comments