Skip to content

get_confidence函数中随着迭代过程,confidence / num_tokens不应该是越低越好吗,如果logits分布比较均匀,confidence / num_tokens应该会很高吧 #2

Description

@ljzx20

def get_confidence(
model,
inputs,
thought_idx,
thought_hidden_states,
k=10,
):
inputs['inputs_embeds'][0, thought_idx[0]:thought_idx[1]] = thought_hidden_states
logits = model(**inputs, return_dict=True)['logits'][0]
probs = torch.softmax(logits, dim=-1)
confidence = 0.0
for idx in range(thought_idx[0], thought_idx[1] + 1):
topk = torch.topk(probs[idx], k=k, largest=True)[0]
confidence -= torch.sum(torch.log(topk + 1e-10)) / k
num_tokens = thought_idx[1] - thought_idx[0] + 1
return confidence / num_tokens

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions