AST Problem¶
astra_rl.methods.ast_problem
¶
ast_problem.py ASTProblem
ASTEnvironment
¶
Bases: Environment[str, str]
The ASTPrompter Rollout Environment
Implements https://arxiv.org/abs/2407.09447.
Specifically, this is the original rollout system used in the ASTPrompter paper, the case of red-teaming where we have the attacker and defender generates successive turns of strings, each of which is appended to the prompt of the other. They do not have IFT or other types of structure.
For usage examples, see astra_rl.core.environment.Environment
.
Attributes:
Name | Type | Description |
---|---|---|
problem |
ASTProblem
|
The problem instance that defines the environment and actions. |
prompts |
Sequence[str]
|
A sequence of initial prompts to start the rollout. |
tree_width |
int
|
The number of branches at each node in the rollout tree. |
tree_depth |
int
|
The depth of the rollout tree. |
Generics
StateT (str): The type of the state in the environment, which is a string. ActionT (str): The type of the action in the environment, which is also a string.
Source code in src/astra_rl/methods/ast_problem.py
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 |
|
ASTEvaluator
¶
Bases: Evaluator[str, str, str]
Evaluator for AST problems.
This class provides methods to evaluate the performance of an ASTProblem.
For usage examples, see astra_rl.core.evaluator.Evaluator
.
Source code in src/astra_rl/methods/ast_problem.py
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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
aggregate_metrics(all_metrics)
¶
Aggregate metrics across multiple rollout graphs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_metrics
|
List[GraphMetrics]
|
A list of metrics from multiple rollout graphs. |
required |
Note
This method should define how to aggregate the metrics, e.g., by averaging or summing them, producing
Returns:
Name | Type | Description |
---|---|---|
JSONLike |
JSONLike
|
The aggregated metrics. |
Source code in src/astra_rl/methods/ast_problem.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
ASTProblem
¶
Bases: Problem[str, str]
Adaptive Stress Testing for Large Language Model Red-Teaming.
Implements https://arxiv.org/abs/2407.09447.
For usage examples, see astra_rl.core.problem.Problem
.
Attributes:
Name | Type | Description |
---|---|---|
moderator |
Moderator
|
The moderator used to evaluate the sequences. |
ppl_weight |
float
|
Weight for perplexity in the reward calculation. |
combined_weight |
float
|
Weight for combined scores in the reward calculation. |
defense_toxicity_weight |
float
|
Weight for defense toxicity in the reward calculation. |
Source code in src/astra_rl/methods/ast_problem.py
19 20 21 22 23 24 25 26 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 |
|