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

feat: Enable isolated node eval for answer generator nodes (incl. OpenAI Node) #3036

Merged
merged 4 commits into from Aug 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions haystack/nodes/answer_generator/base.py
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