Skip to content

Commit

Permalink
Pretty-printing of Model objects
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 629571604
  • Loading branch information
iftenney authored and LIT team committed May 1, 2024
1 parent a5265a4 commit 4fb3bde
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lit_nlp/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ def description(self) -> str:
"""
return inspect.getdoc(self) or ''

def __str__(self) -> str:
classname = self.__class__.__module__ + '.' + self.__class__.__qualname__
indented_description = ' ' + self.description().replace('\n', '\n ')
return f'{classname}(...):\n{indented_description}'

def _repr_pretty_(self, p, cycle):
"""Pretty-printing for IPython environments, both notebooks and repl."""
if not cycle:
p.text(str(self))
else:
p.text('...')

@classmethod
def init_spec(cls) -> Optional[Spec]:
"""Attempts to infer a Spec describing a Model's constructor parameters.
Expand Down

0 comments on commit 4fb3bde

Please sign in to comment.