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

add repr method for Rule, Dataset. #2148

Merged
merged 4 commits into from Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions src/argilla/client/datasets.py
Expand Up @@ -656,6 +656,21 @@ def prepare_for_training(self) -> "datasets.Dataset":
ds_dict, features=datasets.Features(feature_dict)
)

def __repr__(self):
Ankush-Chander marked this conversation as resolved.
Show resolved Hide resolved
header_string = (
f"{''.ljust(4)}\t{'text'.ljust(30)}\t{'annotation'}\t{'prediction'}"
)
repr_list = [
f"{str(i).ljust(4)}\t{rec.text[:30].ljust(30)}\t{str(rec.annotation).ljust(10)}\t{str(rec.prediction).ljust(10)}"
for i, rec in enumerate(self._records[:5])
]
record_string = "\n".join(repr_list)
count_string = f"{len(self._records)} TextClassificationRecord records"
return "\n".join([header_string, record_string, "...", count_string])

def __str__(self):
return repr(self)


class Framework(Enum):
TRANSFORMERS = "transformers"
Expand Down
8 changes: 8 additions & 0 deletions src/argilla/labeling/text_classification/rule.py
Expand Up @@ -172,6 +172,14 @@ def __call__(
else:
return self._label

def __repr__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great:)

"""The rule representation."""
return f"Rule(query='{self.query}', label='{self.label}', name='{self.name}')"

def __str__(self):
"""The rule string representation."""
return repr(self)


def add_rules(dataset: str, rules: List[Rule]):
"""Adds the rules to a given dataset
Expand Down