From 2fc0731f312e6e53e11f96bcaa86f3a5345d1f71 Mon Sep 17 00:00:00 2001 From: Kurt Shuster Date: Tue, 20 Jul 2021 15:31:40 -0400 Subject: [PATCH] handle nan in scores (#3818) --- parlai/agents/rag/retrievers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/parlai/agents/rag/retrievers.py b/parlai/agents/rag/retrievers.py index f303095cda4..bfff0fb77ba 100644 --- a/parlai/agents/rag/retrievers.py +++ b/parlai/agents/rag/retrievers.py @@ -640,6 +640,13 @@ def index_retrieve( vectors = vectors[:, :, :-1] # recompute exact FAISS scores scores = torch.bmm(query.unsqueeze(1), vectors.transpose(1, 2)).squeeze(1) + if torch.isnan(scores).sum().item(): + logging.error( + '\n[ Document scores are NaN; please look into the built index. ]\n' + '[ If using a compressed index, try building an exact index: ]\n' + '[ $ python index_dense_embeddings --indexer-type exact... ]' + ) + scores.fill_(1) ids = torch.tensor([[int(s) for s in ss] for ss in ids]) return ids, scores