Data Utils¶
Input Example¶
Input Features¶
Fewshot Sampler¶
- class FewShotSampler(num_examples_total: Optional[int] = None, num_examples_per_label: Optional[int] = None, also_sample_dev: Optional[bool] = False, num_examples_total_dev: Optional[int] = None, num_examples_per_label_dev: Optional[int] = None)[source]¶
Few-shot learning is an important scenario for prompt-learning, this is a sampler that samples few examples over each class.
- Parameters
num_examples_total (
int
, optional) – Sampling strategyI
: Use total number of examples for few-shot sampling.num_examples_per_label (
int
, optional) – Sampling strategyII
: Use the number of examples for each label for few-shot sampling.also_sample_dev (
bool
, optional) – Whether to apply the sampler to the dev data.num_examples_total_dev (
int
, optional) – Sampling strategyI
: Use total number of examples for few-shot sampling.num_examples_per_label_dev (
int
, optional) – Sampling strategyII
: Use the number of examples for each label for few-shot sampling.
- sample_total(indices: List, num_examples_total)[source]¶
Use the total number of examples for few-shot sampling (Strategy
I
).- Parameters
indices (
List
) – The random indices of the whole datasets.num_examples_total (
int
) – The total number of examples.
- Returns
The selected indices with the size of
num_examples_total
.- Return type
List
- sample_per_label(indices: List, labels, num_examples_per_label)[source]¶
Use the number of examples per class for few-shot sampling (Strategy
II
). If the number of examples is not enough, a warning will pop up.- Parameters
indices (
List
) – The random indices of the whole datasets.labels (
List
) – The list of the labels.num_examples_per_label (
int
) – The total number of examples for each class.
- Returns
The selected indices with the size of
num_examples_total
.- Return type
List