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

Method process_results

lm-eval-harness/lm_eval/api/task.py:1176–1355  ·  view source on GitHub ↗
(self, doc, results)

Source from the content-addressed store, hash-verified

1174 )
1175
1176 def process_results(self, doc, results):
1177 if callable(self.config.process_results):
1178 return self.config.process_results(doc, results)
1179
1180 result_dict = {}
1181 use_metric = list(self._metric_fn_list.keys())
1182 if self.OUTPUT_TYPE == "loglikelihood":
1183 results = results[0]
1184 ll, is_greedy = results
1185 return {
1186 **({"perplexity": ll} if "perplexity" in use_metric else {}),
1187 **({"acc": int(is_greedy)} if "acc" in use_metric else {}),
1188 }
1189 elif self.OUTPUT_TYPE == "loglikelihood_rolling":
1190 (loglikelihood,) = results
1191 _words = self.count_words(self.doc_to_target(doc))
1192 _bytes = self.count_bytes(self.doc_to_target(doc))
1193 return {
1194 **(
1195 {"word_perplexity": (loglikelihood, _words)}
1196 if "word_perplexity" in use_metric
1197 else {}
1198 ),
1199 **(
1200 {"byte_perplexity": (loglikelihood, _bytes)}
1201 if "byte_perplexity" in use_metric
1202 else {}
1203 ),
1204 **(
1205 {"bits_per_byte": (loglikelihood, _bytes)}
1206 if "bits_per_byte" in use_metric
1207 else {}
1208 ),
1209 }
1210 elif self.OUTPUT_TYPE == "multiple_choice":
1211 lls, is_greedy = zip(*results)
1212
1213 # retrieve choices in List[str] form, to compute choice lengths, etc.
1214 choices = self.doc_to_choice(doc)
1215 completion_len = np.array([float(len(i)) for i in choices])
1216
1217 if (
1218 2 * len(choices) == len(lls)
1219 and "acc_mutual_info" in self._metric_fn_list.keys()
1220 ):
1221 # then we are doing mutual info.
1222 # this stores the "dryrun" / unconditional answer loglikelihoods
1223 lls_unconditional = lls[1::2]
1224 assert len(lls_unconditional) == len(choices)
1225 # and this stores our "regular" conditional loglikelihoods
1226 lls = lls[::2]
1227
1228 pred = np.argmax(lls)
1229 pred_norm = np.argmax(lls / completion_len)
1230
1231 if self.multiple_input:
1232 gold = self.doc_to_text(doc)
1233 else:

Callers

nothing calls this directly

Calls 6

doc_to_targetMethod · 0.95
doc_to_choiceMethod · 0.95
doc_to_textMethod · 0.95
process_resultsMethod · 0.45
count_wordsMethod · 0.45
count_bytesMethod · 0.45

Tested by

no test coverage detected