Fix zero-length norm bug with RM3
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).
@@ -165,8 +165,13 @@ public class Rm3Reranker implements Reranker {
for (String term : vocab) {
float fbWeight = 0.0f;
for (int i = 0; i < docvectors.length; 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);
}
