[SDK] An unknown BLEU smoothing_method silently scores without smoothing, while reason reports the requested name
BaseBLEU validates n_grams and weights eagerly, but smoothing_method is never checked. It is resolved lazily with a getattr default:
def _get_smoothing_func(self) -> "nltk_bleu_score.SmoothingFunction":
return getattr(self._smoother, self.smoothing_method, self._smoother.method0)Any name that is not an attribute of NLTK's SmoothingFunction falls through to method0 — no smoothing — while the class default is method1. Nothing is raised or logged, and reason still reports the name that was asked for.
Repro on 8be91f8, sdks/python:
from opik.evaluation.metrics.heuristics.bleu import SentenceBLEU
out, ref = "The cat sat on the mat today", "A cat was sitting on the mat"
for m in ["method1", "methodd1"]:
r = SentenceBLEU(n_grams=4, smoothing_method=m, track=False).score(output=out, reference=ref)
print(m, r.value, r.reason)method1 0.175672 Sentence-level BLEU (nltk, method=method1): 0.1757
methodd1 0.000000 Sentence-level BLEU (nltk, method=methodd1): 0.0000A one-character typo turns 0.1757 into 0.0000, and the output asserts method=methodd1 was used when method0 was. "" and "not_a_method" behave the same way. Because these are scoring outputs, a silent fallback is worse than a failure here — the number looks plausible and nothing signals that it is not the requested metric.
Suggested fix: validate in __init__ and drop the silent default, raising ValueError listing the available methods. That matches the existing convention in the same constructor — n_grams and weights are already validated eagerly, with a comment explaining why validation belongs before the environment check.
I have the change and tests ready locally: the validation plus a parametrized test_bleu__unknown_smoothing_method__raises_value_error mirroring the existing test_bleu__non_positive_n_grams__raises_value_error, over both SentenceBLEU and CorpusBLEU. Without the fix the new tests fail 8/8; with it, tests/unit/evaluation/metrics/test_heuristics.py is 156 passed, 1 skipped and the full tests/unit run is 6265 passed, 3 skipped (the 3 analytics/test_fork.py errors are a pre-existing macOS-only fork-safety crash, present on unmodified main and not seen on Linux CI).
Happy to open the PR — I wanted to confirm the issue first per CONTRIBUTING, and I need to review the CLA before submitting code.
This is a behaviour change: code passing an invalid smoothing_method today gets method0 silently and would start raising. That seems right for a metric, but it is your call whether it needs a deprecation path.
Found while running the SDK test suite; analysis done with an AI coding agent and every claim above verified by running it.
Source: comet-ml/opik