text
stringlengths
0
15.3k
else:
self._filters = [build_filter_ensemble('none', [['take_first', None]])]
if self.config.use_prompt is not None:
eval_logger.info(f'loading prompt {self.config.use_prompt}')
self.prompt = get_prompt(self.config.use_prompt, self.DATASET_PATH, self.DATASET_NAME)
else:
self.prompt = None
if self.fewshot_docs() is not None:
self.fewshot_rnd = random.Random()
config_sampler: Union[str, Callable] = self.config.fewshot_config.get('sampler', 'default') if self.config.fewshot_config else 'default'
if isinstance(config_sampler, str):
self.sampler = samplers.get_sampler(config_sampler)(list(self.fewshot_docs()), self, rnd=self.fewshot_rnd)
elif callable(config_sampler) and issubclass(config_sampler, samplers.ContextSampler):
self.sampler = config_sampler(docs=list(self.fewshot_docs()), task=self, rnd=self.fewshot_rnd)
else:
raise TypeError(f'fewshot_config.sampler should be a string or callable of ContextSampler type, not {type(config_sampler)}')
self.task_docs = self.eval_docs
self.features = list(self.task_docs.features.keys())
self.multiple_input = 0
self.multiple_target = 0
test_doc = self.task_docs[0]
test_text = self.doc_to_text(test_doc)
test_target = self.doc_to_target(test_doc)
if self.config.doc_to_choice is not None:
test_choice = self.doc_to_choice(test_doc)
if not isinstance(test_choice, list):
eval_logger.error('doc_to_choice must return list')
else:
num_choice = len(test_choice)
if isinstance(test_text, int):
self.multiple_input = num_choice
else:
test_choice = None
if isinstance(test_target, list):
self.multiple_target = len(test_target)
elif isinstance(test_target, int) and test_choice is not None:
test_target = test_choice[test_target]
else:
test_target = str(test_target)
if test_choice is not None:
check_choices = test_choice
else:
check_choices = [test_target]
if self.config.doc_to_choice is not None:
for choice in check_choices:
choice_has_whitespace = True if choice[0].isspace() else False
delimiter_has_whitespace = True if self.config.target_delimiter.rstrip() != self.config.target_delimiter else False
if delimiter_has_whitespace and choice_has_whitespace:
eval_logger.debug(f'Both target_delimiter "{self.config.target_delimiter}" and target choice: "{choice}" have whitespace')
elif not delimiter_has_whitespace and (not choice_has_whitespace):
eval_logger.debug(f'Both target_delimiter "{self.config.target_delimiter}" and target choice: "{choice}" do not have whitespace, ignore if the language you are evaluating on does not require/use whitespace')
def download(self, dataset_kwargs: Optional[Dict[str, Any]]=None) -> None:
self.dataset = datasets.load_dataset(path=self.DATASET_PATH, name=self.DATASET_NAME, **dataset_kwargs if dataset_kwargs is not None else {})
def has_training_docs(self) -> bool:
if self.config.training_split is not None:
return True
else:
return False
def has_validation_docs(self) -> bool:
if self.config.validation_split is not None:
return True
else:
return False
def has_test_docs(self) -> bool:
if self.config.test_split is not None:
return True
else:
return False
def training_docs(self) -> datasets.Dataset:
if self.has_training_docs():
if self.config.process_docs is not None:
return self.config.process_docs(self.dataset[self.config.training_split])
return self.dataset[self.config.training_split]
def validation_docs(self) -> datasets.Dataset:
if self.has_validation_docs():
if self.config.process_docs is not None:
return self.config.process_docs(self.dataset[self.config.validation_split])
return self.dataset[self.config.validation_split]
def test_docs(self) -> datasets.Dataset:
if self.has_test_docs():
if self.config.process_docs is not None:
return self.config.process_docs(self.dataset[self.config.test_split])
return self.dataset[self.config.test_split]
def fewshot_docs(self):
if self.config.fewshot_split is not None:
if self.config.process_docs is not None:
return self.config.process_docs(self.dataset[self.config.fewshot_split])
return self.dataset[self.config.fewshot_split]
elif self.config.fewshot_config is not None and self.config.fewshot_config.get('samples', None) is not None:
if isinstance(self.config.fewshot_config['samples'], list):
return self.config.fewshot_config['samples']
elif callable(self.config.fewshot_config['samples']):