Skip to content

evaluate.py predicts "A" when the API returns no logprob for the option letters, so A-gold questions get credit #31

Open

Description

@damienen

In evaluate.py, eval collects the log probability of " A", " B", " C" and " D" from top_logprobs[-1]. If a letter is missing, it prints a warning and uses -100 for that letter. When none of the four letters comes back, all four scores are -100, and np.argmax returns the first index on a tie, so the prediction is "A". Every question whose gold answer is A is then scored correct without the model having answered, and the only trace is the warning lines.

I have not seen a real API response that omits the letters: the script still calls openai.Completion with logprobs=100, which I could not run, and the repro below feeds it a response with none of them. Treating a fully missing result as wrong (or skipping and counting the item) would avoid the free credit.

Reproduction

The script stubs the openai module and crop (which downloads a tokenizer) and has the stub return top logprobs without any option letter. It then runs evaluate.eval on ten questions, four of which have gold answer A. Needs numpy and pandas; set SRC to a checkout of the repo.

import os, sys, types, argparse
import numpy as np, pandas as pd
src = os.environ.get("SRC", "src")
sys.path.insert(0, src)
# stub crop (GPT-2 BPE download) and openai
crop_mod = types.ModuleType("crop"); crop_mod.crop = lambda s: s; sys.modules["crop"] = crop_mod
oa = types.ModuleType("openai")
class C:
    @staticmethod
    def create(**kw):
        return {"choices": [{"logprobs": {"top_logprobs": [{" the": -1.0, " foo": -2.0}]}}]}
oa.Completion = C; sys.modules["openai"] = oa
import evaluate
golds = ["A", "B", "C", "D", "A", "B", "C", "D", "A", "A"]
test = pd.DataFrame([["q", "a", "b", "c", "d", g] for g in golds])
dev = pd.DataFrame([["q", "a", "b", "c", "d", "A"]])
cors, acc, _ = evaluate.eval(argparse.Namespace(ntrain=1), "x", "davinci", dev, test)
print(f"observed accuracy={acc:.3f}  expected (no valid logit -> wrong)=0.000")
if acc > 0:
    print("REPRODUCED"); sys.exit(1)

Output on main (4450500f923c49f1fb1dd3d99108a0bd9717b660), after the warning lines:

Average accuracy 0.400 - x
observed accuracy=0.400  expected (no valid logit -> wrong)=0.000

Ten questions with gold A, B, C, D, A, B, C, D, A, A give 4 of 10 correct from the fallback alone.

Related

#14 points out that the API returns at most 5 top logprobs, which makes it more likely that some option letters are missing from the response. This issue is about what evaluate.py does then: missing letters get -100, and when all four are missing np.argmax picks "A", so A-gold questions are scored correct.

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