The test-time loss to use when working on a response to a multiple choice question. :param evaluation_instruction: Instruction to guide the test time evaluation. This will be a prefix to the prompt. :type evaluation_instruction: str :param engine: LLM engine to use
(self,
evaluation_instruction: str,
engine: Union[EngineLM, str] = None,
system_prompt: Variable = None)
| 146 | |
| 147 | class MultiChoiceTestTime(Module): |
| 148 | def __init__(self, |
| 149 | evaluation_instruction: str, |
| 150 | engine: Union[EngineLM, str] = None, |
| 151 | system_prompt: Variable = None): |
| 152 | """ |
| 153 | The test-time loss to use when working on a response to a multiple choice question. |
| 154 | |
| 155 | :param evaluation_instruction: Instruction to guide the test time evaluation. This will be a prefix to the prompt. |
| 156 | :type evaluation_instruction: str |
| 157 | :param engine: LLM engine to use for the test-time loss computation. |
| 158 | :type engine: EngineLM |
| 159 | :param system_prompt: System prompt for the test-time loss computation, defaults to None |
| 160 | :type system_prompt: Variable, optional |
| 161 | """ |
| 162 | super().__init__() |
| 163 | if system_prompt: |
| 164 | self.tt_system_prompt = system_prompt |
| 165 | else: |
| 166 | tt_system_prompt = DEFAULT_TEST_TIME |
| 167 | self.tt_system_prompt = Variable(tt_system_prompt, |
| 168 | requires_grad=False, |
| 169 | role_description="system prompt for the test-time evaluation") |
| 170 | |
| 171 | if ((engine is None) and (SingletonBackwardEngine().get_engine() is None)): |
| 172 | raise Exception("No engine provided. Either provide an engine as the argument to this call, or use `textgrad.set_backward_engine(engine)` to set the backward engine.") |
| 173 | elif engine is None: |
| 174 | engine = SingletonBackwardEngine().get_engine() |
| 175 | if isinstance(engine, str): |
| 176 | engine = get_engine(engine) |
| 177 | self.engine = engine |
| 178 | format_string = "{instruction}\nQuestion: {{question}}\nAnswer by the language model: {{prediction}}" |
| 179 | self.format_string = format_string.format(instruction=evaluation_instruction) |
| 180 | self.fields = {"prediction": None, "question": None} |
| 181 | self.formatted_llm_call = FormattedLLMCall(engine=self.engine, |
| 182 | format_string=self.format_string, |
| 183 | fields=self.fields, |
| 184 | system_prompt=self.tt_system_prompt) |
| 185 | |
| 186 | def forward(self, question: str, prediction: Variable) -> Variable: |
| 187 | question_variable = Variable(question, |
nothing calls this directly
no test coverage detected