MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / get_result

Function get_result

test/general/lm_eval/models/gpt3.py:10–35  ·  view source on GitHub ↗

Process results from OpenAI API response. :param response: dict OpenAI API Response :param ctxlen: int Length of context (so we can slice them away and only keep the predictions) :return: continuation_logprobs: np.array Log probabilities of continuati

(response, ctxlen)

Source from the content-addressed store, hash-verified

8
9
10def get_result(response, ctxlen):
11 """Process results from OpenAI API response.
12
13 :param response: dict
14 OpenAI API Response
15 :param ctxlen: int
16 Length of context (so we can slice them away and only keep the predictions)
17 :return:
18 continuation_logprobs: np.array
19 Log probabilities of continuation tokens
20 is_greedy: bool
21 whether argmax matches given continuation exactly
22 """
23 is_greedy = True
24 logprobs = response["logprobs"]["token_logprobs"]
25 continuation_logprobs = sum(logprobs[ctxlen:])
26
27 for i in range(ctxlen, len(response["logprobs"]["tokens"])):
28 token = response["logprobs"]["tokens"][i]
29 top_tokens = response["logprobs"]["top_logprobs"][i]
30 top_token = max(top_tokens.keys(), key=lambda x: top_tokens[x])
31 if top_token != token:
32 is_greedy = False
33 break
34
35 return continuation_logprobs, is_greedy
36
37
38def oa_completion(**kwargs):

Callers 1

_loglikelihood_tokensMethod · 0.85

Calls 1

sumFunction · 0.85

Tested by

no test coverage detected