Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor DensePassageRetriever._get_predictions #642

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions haystack/retriever/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def retrieve(self, query: str, filters: dict = None, top_k: int = 10, index: str
documents = self.document_store.query_by_embedding(query_emb=query_emb[0], top_k=top_k, filters=filters, index=index)
return documents

def _get_predictions(self, dicts, tokenizer):
def _get_predictions(self, dicts):
"""
Feed a preprocessed dataset to the model and get the actual predictions (forward pass + formatting).

Expand Down Expand Up @@ -170,7 +170,7 @@ def _get_predictions(self, dicts, tokenizer):
)
all_embeddings = {"query": [], "passages": []}
self.model.eval()
for i, batch in enumerate(tqdm(data_loader, desc=f"Inferencing Samples", unit=" Batches", disable=False)):
for i, batch in enumerate(tqdm(data_loader, desc=f"Creating Embeddings", unit=" Batches", disable=False)):
batch = {key: batch[key].to(self.device) for key in batch}

# get logits
Expand All @@ -195,7 +195,7 @@ def embed_queries(self, texts: List[str]) -> List[np.array]:
:return: Embeddings, one per input queries
"""
queries = [{'query': q} for q in texts]
result = self._get_predictions(queries, self.query_tokenizer)["query"]
result = self._get_predictions(queries)["query"]
return result

def embed_passages(self, docs: List[Document]) -> List[np.array]:
Expand All @@ -211,7 +211,7 @@ def embed_passages(self, docs: List[Document]) -> List[np.array]:
"label": d.meta["label"] if d.meta and "label" in d.meta else "positive",
"external_id": d.id}]
} for d in docs]
embeddings = self._get_predictions(passages, self.passage_tokenizer)["passages"]
embeddings = self._get_predictions(passages)["passages"]

return embeddings

Expand Down