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

__str__ and __repr__ not ideal in MultiLabel dataclass #1972

Closed
mathislucka opened this issue Jan 6, 2022 · 0 comments · Fixed by #2202
Closed

__str__ and __repr__ not ideal in MultiLabel dataclass #1972

mathislucka opened this issue Jan 6, 2022 · 0 comments · Fixed by #2202
Assignees

Comments

@mathislucka
Copy link
Member

Describe the bug
While running some code using haystack I stumbled upon an issue where I always had a list of seemingly empty dicts when getting aggregated labels from a document store. Turns out the issue is just that repr and str are broken on MultiLabel because the data class is missing annotations.

Expected behavior
I'm not sure but I think for asdict() to work we need annotations like in the other data classes. So MultiLabel should probably look like this:

@dataclass
class MultiLabel:
    labels: List[Label]
    query: str
    document_ids: List[str]
    gold_offsets_in_contexts: List[Dict]
    gold_offsets_in_documents: List[Dict]
    answers: List[str]
    no_answer: bool
    document_ids: List[str]
    document_contents: List[str]

    def __init__(self,
                 labels: List[Label],
                 drop_negative_labels=False,
                 drop_no_answers=False
                 ):
#...

Additionally, I realized there are some inconsistencies between Label and MultiLabel and other data classes such as Document or Answer. While those have some nicely formatted output such as "<Answer ... >", Label and MultiLabel simply have their dict versions as representations. This could be confusing when the underlying data class shows different behaviour from an actual dict.

Additional context
Add any other context about the problem here, like document types / preprocessing steps / settings of reader etc.

To Reproduce
Steps to reproduce the behavior

FAQ Check

System:

  • OS:
  • GPU/CPU:
  • Haystack version (commit or version number):
  • DocumentStore:
  • Reader:
  • Retriever:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants