Commit 9b20e2d0 authored by lintangsutawika's avatar lintangsutawika
Browse files

update choice process

parent 656c310e
...@@ -67,7 +67,7 @@ class TaskConfig(dict): ...@@ -67,7 +67,7 @@ class TaskConfig(dict):
template_aliases: Union[str, list] = None template_aliases: Union[str, list] = None
doc_to_text: Union[Callable, str] = None doc_to_text: Union[Callable, str] = None
doc_to_target: Union[Callable, str] = None doc_to_target: Union[Callable, str] = None
doc_to_choice: Union[Callable, str] = None doc_to_choice: Union[Callable, str, dict, list] = None
gold_alias: Union[Callable, str] = None gold_alias: Union[Callable, str] = None
use_prompt: str = None use_prompt: str = None
description: str = "" description: str = ""
...@@ -317,11 +317,9 @@ class Task(abc.ABC): ...@@ -317,11 +317,9 @@ class Task(abc.ABC):
def doc_to_choice(self, doc): def doc_to_choice(self, doc):
if self._config.doc_to_choice is None: if self._config.doc_to_choice is None:
return ast.literal_eval( eval_logger.error("doc_to_choice was callsed but not set in config")
utils.apply_template( elif type(self._config.doc_to_choice) == list:
self._config.template_aliases + "{{answer_choices}}", doc return self._config.doc_to_choice
)
)
elif type(self._config.doc_to_choice) == dict: elif type(self._config.doc_to_choice) == dict:
return list(self._config.doc_to_choice.values()) return list(self._config.doc_to_choice.values())
elif type(self._config.doc_to_choice) == str: elif type(self._config.doc_to_choice) == str:
...@@ -761,6 +759,9 @@ class ConfigurableTask(Task): ...@@ -761,6 +759,9 @@ class ConfigurableTask(Task):
if type(doc_to_target) == str: if type(doc_to_target) == str:
if doc_to_target in self.features: if doc_to_target in self.features:
if self._config.doc_to_choice is not None:
return self.doc_to_choice(doc)[doc[doc_to_target]]
else:
return doc[doc_to_target] return doc[doc_to_target]
else: else:
return utils.apply_template(doc_to_target, doc) return utils.apply_template(doc_to_target, doc)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment