Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
handle nan in scores (#3818)
Browse files Browse the repository at this point in the history
  • Loading branch information
klshuster authored Jul 20, 2021
1 parent 0c7cd04 commit 2fc0731
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions parlai/agents/rag/retrievers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fc0731

Please sign in to comment.