Skip to content

Commit 40742a9

Browse files
authored
[BP] Fix unbiased ltr with training continuation. (dmlc#10908) (dmlc#10909)
1 parent 6b4d703 commit 40742a9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/objective/lambdarank_obj.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class LambdaRankObj : public FitIntercept {
314314
CHECK_EQ(info.weights_.Size(), n_groups) << error::GroupWeight();
315315
}
316316

317-
if (ti_plus_.Size() == 0 && param_.lambdarank_unbiased) {
317+
if ((ti_plus_.Empty() || li_full_.Empty()) && param_.lambdarank_unbiased) {
318318
CHECK_EQ(iter, 0);
319319
ti_plus_ = linalg::Constant<double>(ctx_, 1.0, p_cache_->MaxPositionSize());
320320
tj_minus_ = linalg::Constant<double>(ctx_, 1.0, p_cache_->MaxPositionSize());

tests/python/test_ranking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ def after_training(self, model) -> bool:
202202
# less biased on low ranks.
203203
assert df["ti+"].iloc[-1] < df["ti+"].iloc[0]
204204

205+
# Training continuation
206+
ltr.fit(x, c, qid=q, eval_set=[(x, c)], eval_qid=[q], xgb_model=ltr)
207+
# normalized
208+
np.testing.assert_allclose(df["ti+"].iloc[0], 1.0)
209+
np.testing.assert_allclose(df["tj-"].iloc[0], 1.0)
210+
205211

206212
def test_normalization() -> None:
207213
run_normalization("cpu")

0 commit comments

Comments
 (0)