All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.anserini.rerank.lib.ScoreTiesAdjusterReranker Maven / Gradle / Ivy

/*
 * Anserini: A Lucene toolkit for reproducible information retrieval research
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.anserini.rerank.lib;

import io.anserini.rerank.Reranker;
import io.anserini.rerank.RerankerContext;
import io.anserini.rerank.ScoredDocuments;

/**
 * Reranker that perturbs score ties a tiny bit so that the rank order is consistent
 * with the score sort order.
 */
public class ScoreTiesAdjusterReranker implements Reranker {
  @Override
  public ScoredDocuments rerank(ScoredDocuments docs, RerankerContext context) {

    if (context != null && context.getSearchArgs().arbitraryScoreTieBreak) {
      return docs;
    }

    int dup = 0;
    for (int i=0; i 1e-4f ) {
        dup = 0;
      } else {
        dup++;
        docs.scores[i] -= 1e-6f * dup;
      }
    }

    return docs;
  }
  
  @Override
  public String tag() { return ""; }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy