Skip to content

Instantly share code, notes, and snippets.

@remi-or
Last active January 17, 2022 18:22
Show Gist options
  • Save remi-or/8c881d812c2451043e5483d3d4b522d1 to your computer and use it in GitHub Desktop.
Save remi-or/8c881d812c2451043e5483d3d4b522d1 to your computer and use it in GitHub Desktop.
from typing import Any
from transformers import AutoModelForMaskedLM
roberta = AutoModelForMaskedLM.from_pretrained("roberta-large")
def visualize_children(
object : Any,
level : int = 0,
) -> None:
"""
Prints the children of (object) and their children too, if there are any.
Uses the current depth (level) to print things in a ordonnate manner.
"""
print(f"{' ' * level}{level}- {type(object).__name__}")
try:
for child in object.children():
visualize_children(child, level + 1)
except:
pass
visualize_children(roberta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment