Verifiers integration¶
RL reward functions and a multi-turn environment that plug GAZE processors into the verifiers package for training with verifiable rewards. For the end-to-end setup, see Verifiers integration.
verifiers ¶
Verifiers integration utilities for GAZE.
First-class integration with the verifiers package for multi-turn RL training.
Key components: - VerifiableProcessorMixin: Add verifiers support to any processor - BaseMultiTurnEnv: Standard multi-turn environment template - Reward functions: ExactMatch, TokenF1, IoU, Combined
GazeAdapter, BaseMultiTurnEnv, and VerifiableProcessorMixin
require the verifiers and datasets packages at runtime. They are lazily
imported so that from gaze.verifiers import ExactMatchReward (and
the other reward utilities) works without those heavy optional dependencies.
BaseRewardFunction ¶
Bases: ABC
Base class for reward functions.
Provides a common interface for reward functions that can be used with the verifiers package.
Source code in src/gaze/verifiers/rewards.py
__call__
abstractmethod
¶
Compute reward for a completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The input prompt |
required |
completion
|
Any
|
Model completion |
required |
info
|
dict[str, Any]
|
Additional information (e.g., ground truth) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Reward value (typically 0.0 to 1.0) |
Source code in src/gaze/verifiers/rewards.py
CombinedReward ¶
Bases: BaseRewardFunction
Combine multiple reward functions with weights.
Source code in src/gaze/verifiers/rewards.py
__init__ ¶
__init__(
rewards: list[BaseRewardFunction],
weights: list[float] | None = None,
names: list[str] | None = None,
) -> None
Initialize combined reward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rewards
|
list[BaseRewardFunction]
|
List of reward functions |
required |
weights
|
list[float] | None
|
List of weights (must sum to 1.0) |
None
|
names
|
list[str] | None
|
Optional names for each reward |
None
|
Source code in src/gaze/verifiers/rewards.py
__call__ ¶
Compute combined reward.
Source code in src/gaze/verifiers/rewards.py
ExactMatchReward ¶
Bases: BaseRewardFunction
Exact match reward function.
Rewards 1.0 for exact match, 0.0 otherwise. Supports normalization to handle common variations.
Source code in src/gaze/verifiers/rewards.py
__init__ ¶
__init__(
normalize: bool = True,
case_sensitive: bool = False,
strip_braces: bool = True,
) -> None
Initialize exact match reward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
bool
|
Whether to normalize strings (lowercase, strip) |
True
|
case_sensitive
|
bool
|
If False, compare case-insensitively |
False
|
strip_braces
|
bool
|
Whether to strip braces and punctuation |
True
|
Source code in src/gaze/verifiers/rewards.py
__call__ ¶
Compute exact match reward.
Source code in src/gaze/verifiers/rewards.py
IoUReward ¶
Bases: BaseRewardFunction
Intersection over Union (IoU) reward for bounding boxes.
Rewards based on spatial overlap between predicted and reference boxes. Uses continuous IoU values by default to provide smooth gradient signal for RL training. A step-function mode is available for binary rewards.
Includes an optional area penalty to discourage degenerate full-image predictions that trivially overlap any ground-truth box.
Source code in src/gaze/verifiers/rewards.py
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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
__init__ ¶
__init__(
iou_threshold: float = 0.5,
normalized: bool = True,
continuous: bool = True,
area_penalty_start: float = 0.5,
) -> None
Initialize IoU reward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iou_threshold
|
float
|
IoU threshold used only in step mode |
0.5
|
normalized
|
bool
|
Whether coordinates are normalized [0,1] |
True
|
continuous
|
bool
|
If True (default), return raw IoU for smooth gradients. If False, return 1.0 when IoU >= threshold, else 0.0. |
True
|
area_penalty_start
|
float
|
Area ratio above which penalty begins. When normalized=True, image area is 1.0. A box covering >50% of the image starts getting penalized. Set to 1.0 to disable. |
0.5
|
Source code in src/gaze/verifiers/rewards.py
__call__ ¶
Compute IoU reward.
Source code in src/gaze/verifiers/rewards.py
TokenF1Reward ¶
Bases: BaseRewardFunction
Token-level F1 reward function.
Computes token overlap between prediction and reference. Useful for evaluating text generation where exact match is too strict.
Source code in src/gaze/verifiers/rewards.py
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 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 | |
__init__ ¶
__init__(
normalize: bool = True,
case_sensitive: bool = False,
tokenize: str = "simple",
filter_stopwords: bool = True,
) -> None
Initialize token F1 reward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
bool
|
Whether to normalize strings |
True
|
case_sensitive
|
bool
|
Whether comparison is case-sensitive |
False
|
tokenize
|
str
|
Tokenization method |
'simple'
|
filter_stopwords
|
bool
|
Whether to remove stopwords before scoring |
True
|
Source code in src/gaze/verifiers/rewards.py
__call__ ¶
Compute token F1 reward.
Source code in src/gaze/verifiers/rewards.py
GazeAdapter ¶
Adapter for using GAZE processors with verifiers.
Bridges the gap between the two packages: - Converts messages between formats - Collects tool calls and results from processor runs - Manages image metadata
Source code in src/gaze/verifiers/adapter.py
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 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 | |
__init__ ¶
Initialize adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
AgenticProcessorBase
|
GAZE processor |
required |
process_verifiers_messages
async
¶
Process messages using GAZE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Messages
|
verifiers format messages |
required |
info
|
dict[str, Any]
|
Additional information (may include 'image_path') |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Processed result with response and metadata |
Source code in src/gaze/verifiers/adapter.py
create_environment_class ¶
create_environment_class(
base_class: type[MultiTurnEnv] | None = None,
**env_kwargs: Any,
) -> type[vf.MultiTurnEnv]
Create a verifiers MultiTurnEnv class that uses this adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_class
|
type[MultiTurnEnv] | None
|
Base environment class to inherit from |
None
|
**env_kwargs
|
Any
|
Additional arguments for environment |
{}
|
Returns:
| Type | Description |
|---|---|
type[MultiTurnEnv]
|
Environment class |
Source code in src/gaze/verifiers/adapter.py
BaseMultiTurnEnv ¶
Bases: MultiTurnEnv
Base multi-turn environment for GAZE integration.
Provides common functionality for multi-turn environments: - Dataset loading from JSONL files - Turn tracking and limits - Standard message processing - Logging utilities - Tool request parsing
Subclasses should implement: - setup_state: Initialize episode state - env_response: Generate environment responses
Source code in src/gaze/verifiers/base.py
18 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 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 | |
__init__ ¶
__init__(
cases: list[dict[str, Any]] | None = None,
*,
dataset_path: str | None = None,
max_turns: int = 10,
name: str = "BaseGazeEnv",
log_dir: Path | str | None = None,
) -> None
Initialize environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cases
|
list[dict[str, Any]] | None
|
Pre-loaded cases (optional) |
None
|
dataset_path
|
str | None
|
Path to JSONL dataset file |
None
|
max_turns
|
int
|
Maximum conversation turns |
10
|
name
|
str
|
Environment name |
'BaseGazeEnv'
|
log_dir
|
Path | str | None
|
Directory for debug logs |
None
|
Source code in src/gaze/verifiers/base.py
get_system_prompt ¶
Get system prompt for the environment.
Override this method to provide custom system prompt.
Returns:
| Type | Description |
|---|---|
str
|
System prompt string |
Source code in src/gaze/verifiers/base.py
setup_state
async
¶
Initialize episode state.
Override this method to customize initial state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
State dict pre-populated by verifiers |
required |
Returns:
| Type | Description |
|---|---|
State
|
State with custom fields added |
Source code in src/gaze/verifiers/base.py
env_response
async
¶
Generate environment response to assistant message.
Override this method to implement custom environment behavior. Mutate state in-place to track turn progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Messages
|
Conversation messages |
required |
state
|
State
|
Current episode state (mutate in-place) |
required |
**kwargs
|
Any
|
Additional arguments from verifiers |
{}
|
Returns:
| Type | Description |
|---|---|
Messages
|
Response messages |
Source code in src/gaze/verifiers/base.py
VerifiableProcessorMixin ¶
Mixin that adds verifiers integration to AgenticProcessorBase subclasses.
Provides methods for: - Creating verifiers environments from processors - Defining task-specific reward functions - Converting between GAZE and verifiers formats
Usage
class MyProcessor(VerifiableProcessorMixin, AgenticProcessorBase): def get_reward_function(self) -> BaseRewardFunction: return ExactMatchReward()
# ... implement other abstract methods ...
Create verifiers environment¶
env_class = MyProcessor.as_verifiers_env()
Source code in src/gaze/verifiers/mixin.py
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 | |
get_reward_function
abstractmethod
¶
Return the reward function for this task.
Must be implemented by subclasses to provide task-specific rewards.
Returns:
| Type | Description |
|---|---|
BaseRewardFunction
|
Reward function instance compatible with verifiers |
Source code in src/gaze/verifiers/mixin.py
as_verifiers_env
classmethod
¶
as_verifiers_env(
*,
max_turns: int = 10,
cases: list[dict[str, Any]] | None = None,
dataset_path: str | None = None,
image_base_path: Path | None = None,
**processor_kwargs: Any,
) -> type
Create a verifiers MultiTurnEnv class from this processor.
The returned environment class can be used directly with verifiers for training or evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_turns
|
int
|
Maximum conversation turns per episode |
10
|
cases
|
list[dict[str, Any]] | None
|
Pre-loaded cases (optional, alternative to dataset_path) |
None
|
dataset_path
|
str | None
|
Path to JSONL dataset file |
None
|
image_base_path
|
Path | None
|
Base path for resolving relative image paths |
None
|
**processor_kwargs
|
Any
|
Arguments passed to processor init |
{}
|
Returns:
| Type | Description |
|---|---|
type
|
MultiTurnEnv subclass configured with this processor |
Example
EnvClass = NOVAProcessor.as_verifiers_env( max_turns=10, dataset_path="data/train.jsonl", model_name="openai/gpt-4o", ) env = EnvClass()
Source code in src/gaze/verifiers/mixin.py
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 | |
extract_completion_text ¶
Extract text content from a verifiers completion.
Handles multiple formats: - Plain string - Message list with assistant role - Multimodal content lists
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completion
|
Any
|
Model completion in any supported format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Extracted text content |
Source code in src/gaze/verifiers/rewards.py
__getattr__ ¶
Lazy import for verifiers-dependent symbols.
GazeAdapter, BaseMultiTurnEnv, and
VerifiableProcessorMixin pull in verifiers and datasets
at import time. We defer those imports so that lightweight consumers
(e.g. reward functions only) never pay the cost.