-
Notifications
You must be signed in to change notification settings - Fork 19
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
Configurable truncation when rendering text #53
Comments
This is a great idea, I've been thinking about doing something like this for a while but never got around to it. I had some time to take a stab at a basic implementation in #56. It's currently missing tests and I haven't gotten a chance to play around with it much so there may be bugs. I probably won't be able to polish this up for a few weeks, but I figured I'd share now for early feedback. If you want to try it out you should be able to install it with pip install treescope@git+https://github.com/google-deepmind/treescope.git@abbreviation_system |
I actually ran into a design question while prototyping this that I'd appreciate your thoughts on. There are sort of two choices for when to abbreviate:
1 is the easiest to implement. We could sort of fake 2 if we were OK with the following heuristic: If a node could be fully rendered in less than K columns without any abbreviation, don't abbreviate it. Otherwise abbreviate it at fixed depth. But it would be quite difficult to extend this to do a full recursive analysis like the layout algorithms currently do, where abbreviation of one node is based on the size of the node when abbreviating its children, and there is a target width we are trying to reach. (This is because the user can change the expand states interactively in HTML mode, which interact with the abbreviation depth levels, and I don't want to make that logic more complicated or give users any toggles for abbreviation levels.) So, I'm curious whether you think it would be useful to implement something like 2 in this heuristic form? A limitation would be that lines might still become "too long" under this rule if they have many children and the children are all just short enough to not be abbreviated. |
Daniel, thanks so much for taking a look at this! It would be fantastic to land simple version of this soon, which we could start testing out and think about incrementally improving upon. Constant depth seems like a totally reasonable place to start.
This sounds potentially problematic for the use-case I am most concerned about (readable text reprs with line wrapping). So I guess I would lean towards version 1. |
Ok, I've merged a simple version of this, it will be included in v0.1.9. Thanks for the idea and feedback, and let me know if you run into any issues with it! |
Amazing, thanks Daniel!!
…On Mon, Feb 17, 2025 at 10:50 AM Daniel D. Johnson ***@***.***> wrote:
Ok, I've merged a simple version of this, it will be included in v0.1.9.
Thanks for the idea and feedback, and let me know if you run into any
issues with it!
—
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJJFVXCUZHR52IGYZRKNF32QIVNZAVCNFSM6AAAAABU3FO7R6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRTHA4DGMRSGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
[image: danieldjohnson]*danieldjohnson* left a comment
(google-deepmind/treescope#53)
<#53 (comment)>
Ok, I've merged a simple version of this, it will be included in v0.1.9.
Thanks for the idea and feedback, and let me know if you run into any
issues with it!
—
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJJFVXCUZHR52IGYZRKNF32QIVNZAVCNFSM6AAAAABU3FO7R6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRTHA4DGMRSGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hierarchical models can create really large trees of objects.
Treescope has nice control for shrinking reprs with
using_expansion_strategy(max_height=X)
, but this only works well for interactive HTML and displays that never wrap text (e.g., Google Colab). On the command line, long lines wrap around and make reprs unreadable.It would be really nice if Treescope has some built-in support for truncating such really long lines, perhaps by replacing objects with truncated reprs like
<dict>
or{...}
. I would use this for implementing__repr__
methods, e.g., for neural network modules.To reproduce:
Default rendering -- fine on GitHub, but unreadable when pasted into a console:
One very naive attempt at truncation:
Example of what a better truncated repr might look like, with the tree truncated at a consistent depth:
The text was updated successfully, but these errors were encountered: