diff --git a/src/main/java/io/anserini/rerank/lib/Rm3Reranker.java b/src/main/java/io/anserini/rerank/lib/Rm3Reranker.java index 09779de902..b157ae7b13 100644 --- a/src/main/java/io/anserini/rerank/lib/Rm3Reranker.java +++ b/src/main/java/io/anserini/rerank/lib/Rm3Reranker.java @@ -165,7 +165,12 @@ private FeatureVector estimateRelevanceModel(ScoredDocuments docs, IndexReader r for (String term : vocab) { float fbWeight = 0.0f; for (int i = 0; i < docvectors.length; i++) { - fbWeight += (docvectors[i].getFeatureWeight(term) / norms[i]) * docs.scores[i]; + // Avoids zero-length feedback documents, which causes division by zero when computing term weights. + // Zero-length feedback documents occur (e.g., with CAR17) when a document has only terms + // that accents (which are indexed, but not selected for feedback). + if (norms[i] > 0.001f) { + fbWeight += (docvectors[i].getFeatureWeight(term) / norms[i]) * docs.scores[i]; + } } f.addFeatureWeight(term, fbWeight); }