MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / doc_to_choice

Method doc_to_choice

lm-eval-harness/lm_eval/api/task.py:1093–1115  ·  view source on GitHub ↗
(self, doc: Any)

Source from the content-addressed store, hash-verified

1091 raise TypeError
1092
1093 def doc_to_choice(self, doc: Any) -> List[str]:
1094 if self.prompt is not None:
1095 doc_to_choice = self.prompt
1096 elif self.config.doc_to_choice is None:
1097 eval_logger.error("doc_to_choice was called but not set in config")
1098 else:
1099 doc_to_choice = self.config.doc_to_choice
1100
1101 if isinstance(doc_to_choice, str):
1102 if doc_to_choice in self.features:
1103 return doc[doc_to_choice]
1104 else:
1105 return ast.literal_eval(utils.apply_template(doc_to_choice, doc))
1106 elif isinstance(doc_to_choice, list):
1107 return doc_to_choice
1108 elif isinstance(doc_to_choice, dict):
1109 return list(doc_to_choice.values())
1110 elif callable(doc_to_choice):
1111 return doc_to_choice(doc)
1112 elif hasattr(doc_to_choice, "get_answer_choices_list"):
1113 return doc_to_choice.get_answer_choices_list(doc)
1114 else:
1115 raise TypeError
1116
1117 def construct_requests(
1118 self, doc: dict, ctx: str, **kwargs

Callers 5

__init__Method · 0.95
fewshot_contextMethod · 0.95
construct_requestsMethod · 0.95
process_resultsMethod · 0.95
get_contextMethod · 0.80

Calls 1

doc_to_choiceFunction · 0.85

Tested by

no test coverage detected