Extra¶
LoadDataFromDicts
¶
Bases: GeneratorStep
Loads a dataset from a list of dictionaries.
GeneratorStep
that loads a dataset from a list of dictionaries and yields it in
batches.
Attributes:
Name | Type | Description |
---|---|---|
data |
List[Dict[str, Any]]
|
The list of dictionaries to load the data from. |
Runtime parameters
batch_size
: The batch size to use when processing the data.
Output columns
- dynamic (based on the keys found on the first dictionary of the list): The columns of the dataset.
Categories
- load
Examples:
Load data from a list of dictionaries:
```python
from distilabel.steps import LoadDataFromDicts
loader = LoadDataFromDicts(
data=[{"instruction": "What are 2+2?"}] * 5,
batch_size=2
)
loader.load()
result = next(loader.process())
# >>> result
# ([{'instruction': 'What are 2+2?'}, {'instruction': 'What are 2+2?'}], False)
```
Source code in src/distilabel/steps/generators/data.py
outputs: List[str]
property
¶
Returns a list of strings with the names of the columns that the step will generate.
process(offset=0)
¶
Yields batches from a list of dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int
|
The offset to start the generation from. Defaults to |
0
|
Yields:
Type | Description |
---|---|
GeneratorStepOutput
|
A list of Python dictionaries as read from the inputs (propagated in batches) |
GeneratorStepOutput
|
and a flag indicating whether the yield batch is the last one. |
Source code in src/distilabel/steps/generators/data.py
DeitaFiltering
¶
Bases: GlobalStep
Filter dataset rows using DEITA filtering strategy.
Filter the dataset based on the DEITA score and the cosine distance between the embeddings. It's an implementation of the filtering step from the paper 'What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning'.
Attributes:
Name | Type | Description |
---|---|---|
data_budget |
RuntimeParameter[int]
|
The desired size of the dataset after filtering. |
diversity_threshold |
RuntimeParameter[float]
|
If a row has a cosine distance with respect to it's nearest
neighbor greater than this value, it will be included in the filtered dataset.
Defaults to |
normalize_embeddings |
RuntimeParameter[bool]
|
Whether to normalize the embeddings before computing the cosine
distance. Defaults to |
Runtime parameters
data_budget
: The desired size of the dataset after filtering.diversity_threshold
: If a row has a cosine distance with respect to it's nearest neighbor greater than this value, it will be included in the filtered dataset.
Input columns
- evol_instruction_score (
float
): The score of the instruction generated byComplexityScorer
step. - evol_response_score (
float
): The score of the response generated byQualityScorer
step. - embedding (
List[float]
): The embedding generated for the conversation of the instruction-response pair usingGenerateEmbeddings
step.
Output columns
- deita_score (
float
): The DEITA score for the instruction-response pair. - deita_score_computed_with (
List[str]
): The scores used to compute the DEITA score. - nearest_neighbor_distance (
float
): The cosine distance between the embeddings of the instruction-response pair.
Categories
- filtering
Examples:
Filter the dataset based on the DEITA score and the cosine distance between the embeddings:
```python
from distilabel.steps import DeitaFiltering
deita_filtering = DeitaFiltering(data_budget=1)
deita_filtering.load()
result = next(
deita_filtering.process(
[
{
"evol_instruction_score": 0.5,
"evol_response_score": 0.5,
"embedding": [-8.12729941, -5.24642847, -6.34003029],
},
{
"evol_instruction_score": 0.6,
"evol_response_score": 0.6,
"embedding": [2.99329242, 0.7800932, 0.7799726],
},
{
"evol_instruction_score": 0.7,
"evol_response_score": 0.7,
"embedding": [10.29041806, 14.33088073, 13.00557506],
},
],
)
)
# >>> result
# [{'evol_instruction_score': 0.5, 'evol_response_score': 0.5, 'embedding': [-8.12729941, -5.24642847, -6.34003029], 'deita_score': 0.25, 'deita_score_computed_with': ['evol_instruction_score', 'evol_response_score'], 'nearest_neighbor_distance': 1.9042812683723933}]
```
Source code in src/distilabel/steps/deita.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
process(inputs)
¶
Filter the dataset based on the DEITA score and the cosine distance between the embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
StepInput
|
The input data. |
required |
Returns:
Type | Description |
---|---|
StepOutput
|
The filtered dataset. |
Source code in src/distilabel/steps/deita.py
GeneratorStepOutput = Iterator[Tuple[List[Dict[str, Any]], bool]]
module-attribute
¶
GeneratorStepOutput is an alias of the typing Iterator[Tuple[List[Dict[str, Any]], bool]]
StepOutput = Iterator[List[Dict[str, Any]]]
module-attribute
¶
StepOutput is an alias of the typing Iterator[List[Dict[str, Any]]]