Skip to content

Commit 167a792

Browse files
authored
Merge pull request #831 from kritinv/Synthetic-Docs
Docs
2 parents 1929650 + 22d4bc4 commit 167a792

File tree

1 file changed

+76
-6
lines changed

1 file changed

+76
-6
lines changed

docs/docs/evaluation-datasets-synthetic-data.mdx

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ As you'll learn later, an embedding model is only used when using the `generate_
3636

3737
## Using Synthesizer As A Standalone
3838

39-
There are 2 approaches a `deepeval`'s `Synthesizer` can generate synthetic `Golden`s:
39+
There are 4 approaches a `deepeval`'s `Synthesizer` can generate synthetic `Golden`s:
4040

4141
1. Generating synthetic `Golden`s using **context extracted from documents.**
4242
2. Generating synthetic `Golden`s from a **list of provided context.**
43+
3. Generating synthetic `Golden`s from a **list of provided prompts.**
44+
4. Generating synthetic `Golden`s from **scratch**
4345

44-
### Generating From Documents
46+
### 1. Generating From Documents
4547

4648
To generate synthetic `Golden`s from documents, simply provide a list of document paths:
4749

@@ -59,7 +61,7 @@ synthesizer.generate_goldens_from_docs(
5961
)
6062
```
6163

62-
There are one mandatory and six optional parameters when using the `generate_goldens_from_docs` method:
64+
There are one mandatory and seven optional parameters when using the `generate_goldens_from_docs` method:
6365

6466
- `document_paths`: a list strings, representing the path to the documents from which contexts will be extracted from. Supported documents types include: `.txt`, `.docx`, and `.pdf`.
6567
- [Optional] `include_expected_output`: a boolean which when set to `True`, will additionally generate an `expected_output` for each synthetic `Golden`. Defaulted to `False`.
@@ -68,8 +70,9 @@ There are one mandatory and six optional parameters when using the `generate_gol
6870
- [Optional] `chunk_overlap`: an int that determines the overlap size between consecutive text chunks during context extraction. Defaulted to 0.
6971
- [Optional] `num_evolutions`: the number of evolution steps to apply to each generated input. This parameter controls the **complexity and diversity** of the generated dataset by iteratively refining and evolving the initial inputs. Defaulted to 1.
7072
- [Optional] `enable_breadth_evolve`: a boolean which when set to `True`, introduces a **wider variety of context modifications**, enhancing the dataset's diversity. Defaulted to `False`.
73+
- [Optional] `evolution_types`: a list of `Evolution`, specifying methods used during data evolution. Defaulted to all `Evolution`s.
7174

72-
### Generating From Provided Contexts
75+
### 2. Generating From Provided Contexts
7376

7477
`deepeval` also allows you to generate synthetic `Goldens` from a manually provided a list of context instead of directly generating from your documents.
7578

@@ -90,18 +93,85 @@ synthesizer.generate_goldens(
9093
)
9194
```
9295

93-
There are one mandatory and four optional parameters when using the `generate_goldens` method:
96+
There are one mandatory and five optional parameters when using the `generate_goldens` method:
9497

9598
- `contexts`: a list of context, where each context is itself a list of strings, ideally sharing a common theme or subject area.
9699
- [Optional] `include_expected_output`: a boolean which when set to `True`, will additionally generate an `expected_output` for each synthetic `Golden`. Defaulted to `False`.
97100
- [Optional] `max_goldens_per_context`: the maximum number of golden data points to be generated from each context. Adjusting this parameter can influence the size of the resulting dataset. Defaulted to 2.
98101
- [Optional] `num_evolutions`: the number of evolution steps to apply to each generated input. This parameter controls the **complexity and diversity** of the generated dataset by iteratively refining and evolving the initial inputs. Defaulted to 1.
99102
- [Optional] `enable_breadth_evolve`: a boolean indicating whether to enable breadth evolution strategies during data generation. When set to True, it introduces a **wider variety of context modifications**, enhancing the dataset's diversity. Defaulted to `False`.
103+
- [Optional] `evolution_types`: a list of `Evolution`, specifying methods used during data evolution. Defaulted to all `Evolution`s.
100104

101105
:::caution
102-
You can also optionally generate `expected_output`s alongside each golden, but you should always aim to cross-check any generated expected output.
106+
While the previous methods first use an LLM to generate a series of inputs based on the provided context before evolving them, `generate_goldens_from_inputs` simply evolves the provided list of inputs into more complex and diverse `Golden`s. It's also important to note that this method will only populate the input field of each generated `Golden`.
103107
:::
104108

109+
### 3. Generating From Provided Prompts
110+
111+
If your LLM application **does not rely on a retrieval context**, or if you simply wish to generate a synthetic dataset based on information outside your application's information database, `deepeval` also supports generating synthetic `Golden`s from an initial list of prompts, which serve as examples from which additional prompts will be generated.
112+
113+
:::info
114+
While the previous methods first use an LLM to generate a series of inputs based on the provided context before evolving them, `generate_goldens_from_prompts` simply **evolves the provided list of prompts** into more complex and diverse `Golden`s. It's also important to note that this method will only populate the input field of each generated `Golden`.
115+
:::
116+
117+
```python
118+
from deepeval.synthesizer import Synthesizer
119+
120+
synthesizer = Synthesizer()
121+
synthesizer.generate_goldens_from_prompts(
122+
prompts=[
123+
"What is 2+2",
124+
"Give me the solution to 12/5",
125+
"5! = ?"
126+
],
127+
num_evolutions=20
128+
)
129+
```
130+
131+
There are one mandatory and three optional parameters when using the `generate_goldens_from_docs` method:
132+
133+
- `prompts`: a list of strings, representing your initial list of example prompts.
134+
- [Optional] `num_evolutions`: the number of evolution steps to apply to each prompt. This parameter controls the **complexity and diversity** of the generated dataset by iteratively refining and evolving the initial prompts. Defaulted to 1.
135+
- [Optional] `enable_breadth_evolve`: a boolean which when set to `True`, introduces a **wider variety of context modifications**, enhancing the dataset's diversity. Defaulted to `False`.
136+
- [Optional] `evolution_types`: a list of `PromptEvolution`, specifying methods used during data evolution. Defaulted to all `PromptEvolution`s.
137+
138+
### 4. Generating From Scratch
139+
140+
If you do not have a list of example prompts, or wish to solely rely on an LLM generation for synthesis, you can also generate synthetic `Golden`s simply by specifying the subject, task, and output format you wish your prompts to follow.
141+
142+
:::tip
143+
Generating goldens from scratch is especially helpful when you wish to **evaluate your LLM on a specific task**, such as red-teaming or text-to-SQL use cases!
144+
:::
145+
146+
```python
147+
from deepeval.synthesizer import Synthesizer
148+
149+
synthesizer = Synthesizer()
150+
synthesizer.generate_goldens_from_scratch(
151+
subject="Harmful and toxic prompts, with emphasis on dark humor",
152+
task="Red-team LLMs",
153+
output_format="string",
154+
num_initial_goldens=25,
155+
num_evolutions=20
156+
)
157+
```
158+
159+
This method is a **2-step function** that first generates a list of prompts about a given subject for a certain task and in a certain output format, before using the generated list of prompts to generate more prompts through data evolution.
160+
161+
:::info
162+
The subject, task, and output format parameters are all strings that are inserted into a predefined prompt template, meaning these parameters are **flexible and will need to be iterated on** for optimal results.
163+
:::
164+
165+
There are four mandatory and three optional parameters when using the `generate_goldens_from_docs` method:
166+
167+
- `subject`: a string, specifying the subject and nature of your generated `Golden`s
168+
- `task`: a string, representing the purpose of these evaluation `Golden`s
169+
- `output_format`: a string, representing the expected output format. This is not equivalent to python `type`s but simply gives you more control over the structure of your synthetic data.
170+
- `num_initial_goldens`: the number of goldens generated before consequent evolutions
171+
- [Optional] `num_evolutions`: the number of evolution steps to apply to each generated prompt. This parameter controls the **complexity and diversity** of the generated dataset by iteratively refining and evolving the initial inputs. Defaulted to 1.
172+
- [Optional] `enable_breadth_evolve`: a boolean which when set to `True`, introduces a **wider variety of context modifications**, enhancing the dataset's diversity. Defaulted to `False`.
173+
- [Optional] `evolution_types`: a list of `PromptEvolution`, specifying methods used during data evolution. Defaulted to all `PromptEvolution`s.
174+
105175
### Saving Generated Goldens
106176

107177
To not accidentally lose any generated synthetic `Golden`, you can use the `save_as()` method:

0 commit comments

Comments
 (0)