Skip to content

Commit

Permalink
feat: Enable isolated node eval for answer generator nodes (incl. Ope…
Browse files Browse the repository at this point in the history
…nAI Node) (#3036)

* enable isolated node eval for answer generator nodes

* adjust comment

* remove unused import

* fix mypy

Co-authored-by: tstadel <[email protected]>
  • Loading branch information
tholor and tstadel authored Aug 14, 2022
1 parent 4f261a4 commit 1b422ab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions haystack/nodes/answer_generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tqdm.auto import tqdm

from haystack.errors import HaystackError
from haystack.schema import Answer, Document
from haystack.schema import Answer, Document, MultiLabel
from haystack.nodes.base import BaseComponent


Expand All @@ -31,13 +31,19 @@ def predict(self, query: str, documents: List[Document], top_k: Optional[int]) -
"""
pass

def run(self, query: str, documents: List[Document], top_k: Optional[int] = None): # type: ignore
def run(self, query: str, documents: List[Document], top_k: Optional[int] = None, labels: Optional[MultiLabel] = None, add_isolated_node_eval: bool = False): # type: ignore

if documents:
results = self.predict(query=query, documents=documents, top_k=top_k)
else:
results = {"answers": []}

# run evaluation with "perfect" labels as node inputs to calculate "upper bound" metrics for just this node
if add_isolated_node_eval and labels is not None:
relevant_documents = list({label.document.id: label.document for label in labels.labels}.values())
results_label_input = self.predict(query=query, documents=relevant_documents, top_k=top_k)
results["answers_isolated"] = results_label_input["answers"]

return results, "output_1"

def run_batch( # type: ignore
Expand Down

0 comments on commit 1b422ab

Please sign in to comment.