From c93b365f98005df52fc3f8ea72fd45c1c3b96bb2 Mon Sep 17 00:00:00 2001 From: Sara Zan Date: Thu, 17 Feb 2022 16:37:02 +0100 Subject: [PATCH] Improve `Label` and `MultiLabel` `__str__` and `__repr__` (#2202) * Add proper annotation to MultiLabel and slightly improve __str__ for MultiLabel and Label Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- haystack/schema.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/haystack/schema.py b/haystack/schema.py index 461162328..5f27f52ea 100644 --- a/haystack/schema.py +++ b/haystack/schema.py @@ -481,11 +481,20 @@ class Label: return str(self.to_dict()) def __str__(self): - return str(self.to_dict()) + return f"" @dataclass class MultiLabel: + labels: List[Label] + query: str + answers: List[str] + no_answer: bool + document_ids: List[str] + document_contents: List[str] + gold_offsets_in_contexts: List[Dict] + gold_offsets_in_documents: List[Dict] + def __init__(self, labels: List[Label], drop_negative_labels=False, drop_no_answers=False): """ There are often multiple `Labels` associated with a single query. For example, there can be multiple annotated @@ -499,7 +508,6 @@ class MultiLabel: :param drop_negative_labels: Whether to drop negative labels from that group (e.g. thumbs down feedback from UI) :param drop_no_answers: Whether to drop labels that specify the answer is impossible """ - # drop duplicate labels and remove negative labels if needed. labels = list(set(labels)) if drop_negative_labels: @@ -588,7 +596,7 @@ class MultiLabel: return str(self.to_dict()) def __str__(self): - return str(self.to_dict()) + return f"" def _pydantic_dataclass_from_dict(dict: dict, pydantic_dataclass_type) -> Any: