__call__(
eval_inputs: list[dict[str, Any]]
| dict[str, Any]
| None = None,
) -> list[Instance]
Sample instances for few-shot learning.
This method calls _sample_instances
and
checks if the sampled instances have the same inputs as the evaluation instance.
Parameters:
-
eval_inputs
(list[dict[str, Any]] | dict[str, Any] | None
, default:
None
)
–
The inputs of the evaluation instance.
This is used to avoid data leakage
by checking if the sampled instances have the same inputs as the evaluation instance.
Returns:
-
list[Instance]
–
A list of instances for few-shot learning.
Source code in flexeval/core/few_shot_generator/base.py
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 | def __call__(self, eval_inputs: list[dict[str, Any]] | dict[str, Any] | None = None) -> list[Instance]:
"""
Sample instances for few-shot learning.
This method calls `_sample_instances` and
checks if the sampled instances have the same inputs as the evaluation instance.
Args:
eval_inputs: The inputs of the evaluation instance.
This is used to avoid data leakage
by checking if the sampled instances have the same inputs as the evaluation instance.
Returns:
A list of instances for few-shot learning.
"""
sampled_instances = self._sample_instances(eval_inputs=eval_inputs)
# check if the sampled instances are the same as the eval_instance
if self._num_trials_to_avoid_leak and eval_inputs is not None:
for _ in range(self._num_trials_to_avoid_leak):
if all(sampled.inputs != eval_inputs for sampled in sampled_instances):
return sampled_instances
# retry sampling
sampled_instances = self._sample_instances(eval_inputs=eval_inputs)
msg = (
f"Few-shot instance has the same inputs as the evaluation instance, "
f"which indicates a data leak. "
f"Failed to sample a different instance after {self._num_trials_to_avoid_leak} trials."
)
raise ValueError(msg)
return sampled_instances
|