BatchRewardFunctionWrapper reward
Bases: BatchReward
Wrap a stateless batched function into a BatchReward.
The wrapped function receives the full batch and must return a
list[float] of length batch_size. It must be declared with
async def, since reward functions are awaited.
Unlike per-sample functions, a batched function is never auto-wrapped by
compile: its batch -> list[float] signature cannot be told apart
from a per-sample one, so it always has to be passed wrapped in this class.
Example:
async def my_batch_reward(y_true, y_pred):
# y_true, y_pred: list[JsonDataModel] of length batch_size
return [1.0 if t.get_json() == p.get_json() else 0.0
for t, p in zip(y_true, y_pred)]
program.compile(
reward=synalinks.rewards.BatchRewardFunctionWrapper(fn=my_batch_reward),
optimizer=synalinks.optimizers.RandomFewShot(),
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
callable
|
Async batched reward function with signature
|
required |
name
|
str
|
Optional. string name of the reward instance. |
None
|
reduction
|
str
|
Optional. One of |
'mean'
|
in_mask
|
list
|
Optional. |
None
|
out_mask
|
list
|
Optional. |
None
|
in_mask_pattern
|
str
|
Optional. |
None
|
out_mask_pattern
|
str
|
Optional. |
None
|
**kwargs
|
keyword arguments
|
Extra keyword arguments forwarded
to |
{}
|
Source code in synalinks/src/rewards/batch_reward.py
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 | |