(
self, doc: dict, ctx: str, **kwargs
)
| 1115 | raise TypeError |
| 1116 | |
| 1117 | def construct_requests( |
| 1118 | self, doc: dict, ctx: str, **kwargs |
| 1119 | ) -> Union[List[Instance], Instance]: |
| 1120 | if self.OUTPUT_TYPE == "loglikelihood": |
| 1121 | arguments = (ctx, self.doc_to_target(doc)) |
| 1122 | elif self.OUTPUT_TYPE == "loglikelihood_rolling": |
| 1123 | arguments = (self.doc_to_target(doc),) |
| 1124 | elif self.OUTPUT_TYPE == "multiple_choice": |
| 1125 | choices = self.doc_to_choice(doc) |
| 1126 | target_delimiter = self.config.target_delimiter |
| 1127 | if self.multiple_input: |
| 1128 | # If there are multiple inputs, choices are placed in the ctx |
| 1129 | cont = self.doc_to_target(doc) |
| 1130 | arguments = [ |
| 1131 | (ctx + choice, f"{target_delimiter}{cont}") for choice in choices |
| 1132 | ] |
| 1133 | else: |
| 1134 | # Otherwise they are placed in the continuation |
| 1135 | arguments = [(ctx, f"{target_delimiter}{cont}") for cont in choices] |
| 1136 | |
| 1137 | request_list = [ |
| 1138 | Instance( |
| 1139 | request_type="loglikelihood", |
| 1140 | doc=doc, |
| 1141 | arguments=arg, |
| 1142 | idx=i, |
| 1143 | **kwargs, |
| 1144 | ) |
| 1145 | for i, arg in enumerate(arguments) |
| 1146 | ] |
| 1147 | # TODO: we should raise a warning telling users this will at most ~2x runtime. |
| 1148 | if "acc_mutual_info" in self._metric_fn_list.keys(): |
| 1149 | # if we are calculating multiple choice accuracy |
| 1150 | # using mutual information instead of raw loglikelihood as metric, need unconditional lls. |
| 1151 | |
| 1152 | # here mutual info refers to calculating |
| 1153 | # log(P(choice|ctx) / P(choice)) = log(P(choice|ctx)) - log(P(choice)) |
| 1154 | # in other words normalizing by subtracting the unconditional logprob of each choice. |
| 1155 | request_list.extend( |
| 1156 | [ |
| 1157 | Instance( |
| 1158 | request_type="loglikelihood", |
| 1159 | doc=doc, |
| 1160 | arguments=("", "{}".format(choice)), |
| 1161 | idx=i, |
| 1162 | **kwargs, |
| 1163 | ) |
| 1164 | for i, choice in enumerate(choices) |
| 1165 | ] |
| 1166 | ) |
| 1167 | return request_list |
| 1168 | |
| 1169 | elif self.OUTPUT_TYPE == "generate_until": |
| 1170 | arguments = (ctx, self.config.generation_kwargs) |
| 1171 | |
| 1172 | return Instance( |
| 1173 | request_type=self.OUTPUT_TYPE, doc=doc, arguments=arguments, idx=0, **kwargs |
| 1174 | ) |
nothing calls this directly
no test coverage detected