PassHatK metric
Bases: SampledRewardMetric
pass^k: fraction of problems solved in all k samples (consistency).
A batched metric (each batch is one problem's k samples). Unbiased
estimator of the probability that k samples drawn (without replacement)
from the n batch samples are all correct::
pass^k = C(c, k) / C(n, k)
(= 0.0 when c < k). Averaged over the dataset. Always <= the
corresponding PassAtK; the difference is reported by GapK.
Example:
import synalinks
class Question(synalinks.DataModel):
question: str
class Answer(synalinks.DataModel):
answer: str
K = 5
# Sampling (temperature > 0) so the K rollouts of one prompt differ.
inputs = synalinks.Input(data_model=Question)
outputs = await synalinks.Generator(
data_model=Answer,
language_model=synalinks.LanguageModel(model="openai/gpt-4o-mini"),
temperature=0.8,
)(inputs)
program = synalinks.Program(inputs=inputs, outputs=outputs)
program.compile(
reward=synalinks.rewards.ExactMatch(in_mask=["answer"]),
metrics=[synalinks.metrics.PassHatK(k=K)],
)
# repeat == batch_size == K -> each batch is one problem's K samples.
dataset = synalinks.HuggingFaceDataset(
hf_dataset_name="openai/gsm8k",
hf_config_name="main",
split="test",
input_data_model=Question,
output_data_model=Answer,
input_template='{"question": {{ question | tojson }}}',
output_template='{"answer": {{ answer.split("####")[-1].strip() | tojson }}}',
batch_size=K,
repeat=K,
limit=20,
)
metrics = await program.evaluate(x=dataset())
print(metrics["pass_hat_k"]) # consistency: solved in ALL K samples
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
The number of samples |
1
|
reward
|
Reward
|
Per-sample correctness signal (default |
None
|
pass_threshold
|
float
|
Reward threshold for a sample to count as
correct. Defaults to |
1.0
|
name
|
str
|
Optional. Name of the metric instance. |
'pass_hat_k'
|
Source code in synalinks/src/metrics/agents_metrics.py
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 | |