Skip to content

fix(assistantbench): Fix Non-Finite and Negative Numeric Scoring in AssistantBench - #433

Open
Tarunvoff wants to merge 1 commit into
ServiceNow:mainfrom
Tarunvoff:feat/assistantbench-numeric-scoring
Open

Tarunvoff wants to merge 1 commit into
ServiceNow:mainfrom
Tarunvoff:feat/assistantbench-numeric-scoring

Conversation

@Tarunvoff

Copy link
Copy Markdown

Fix Non-Finite and Negative Numeric Scoring in AssistantBench

Closes #420

Summary

distance_function_log in AssistantBench evaluation now includes guards for non-finite values (-inf, inf, nan), negative input pairs, and opposite-sign numbers. This guarantees all numerical accuracy scores are strictly bounded in [0, 1] and prevents run-level average scores from becoming infinite or inflated.

Motivation

As described in #420, distance_function_log in evaluate_numbers.py assumed pred and gold were strictly positive numbers. In practice, agent outputs and task inputs broke this assumption in three ways:

Problem Cause Impact
Non-finite output ("-inf") produces score = inf "-inf" parses to float. For positive gold, gold / pred = 20 / -inf = -0.0. Then log(-0.0) = -inf, yielding 1 - (-inf) = +inf. A single inf destroys the aggregate run metrics, making mean accuracy across the benchmark infinite.
Negative gold inverts the comparison ratio With negative gold, pred > gold evaluates to False (e.g. -5000 > -5 is False). The else branch selects gold / pred = -5 / -5000 = 0.001 < 1. np.log(0.001) is negative, yielding a score of 7.91. An answer with an error of 3 orders of magnitude scores better than a perfect match (1.0).
Opposite-sign inputs cause NaN warnings When one input is positive and one is negative, their ratio is negative, causing log(ratio) to evaluate to NaN. Emits runtime warnings and returns NaN in downstream scoring.

Key Changes

  • Non-finite Guard:

    if not np.isfinite(pred) or not np.isfinite(gold):
        return 0

    Safely catches inf, -inf, and NaN before division or logarithm evaluation.

  • Negative Pair Normalization:

    if pred < 0 and gold < 0:
        pred, gold = -pred, -gold

    Normalizes negative pairs to positive magnitudes so pred > gold correctly identifies the larger magnitude and computes the appropriate log ratio.

  • Opposite-Sign Guard:

    elif pred < 0 or gold < 0:
        return 0

    Immediately returns 0 when signs mismatch or when one input is zero and the other is negative.

Backward Compatibility

  • Zero float drift: The original two formula branches (pred > gold: return max(0, 1 - np.log(pred / gold)) and else: return max(0, 1 - np.log(gold / pred))) are kept intact.
  • Rewriting the expression as 1 - abs(np.log(pred / gold)) alters the least significant float bits due to IEEE 754 division ordering; keeping the two branches ensures exact, bit-for-bit equality against all existing benchmark baselines. All 63 existing tests pass unchanged.

Verification

  • Repro Script:

    # Before:
    pred='-inf'  gold='20'   score=inf
    pred='-inf'  gold='$55'  score=inf
    pred='-5000' gold='-5'   score=7.907755278982137
    
    # After:
    pred='-inf'  gold='20'   score=0
    pred='-inf'  gold='$55'  score=0
    pred='-5000' gold='-5'   score=0
  • Pytest:

    $env:PYTHONPATH="browsergym/assistantbench/src;browsergym/core/src;browsergym/experiments/src"
    python -m pytest tests/assistantbench/test_evaluation.py -m "not slow"
    # Result: 74 passed, 26 deselected in 7.07s (63 baseline + 11 new tests)

Proof of Work

Screenshot 2026-11-25 095814

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AssistantBench number scoring returns inf for the answer "-inf" and scores above 1 for negative golds

1 participant