-
Notifications
You must be signed in to change notification settings - Fork 117
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
Refactor XLNet interface #208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I'm thinking, would this problem be solved if we have a mechanism that can:
- Add methods that is called prior to
__init__
(of the uppermost subclass). - Add methods that is called after
__init__
(of the uppermost subclass).
I feel that such mechanism could solve both this problem and the repeated-hparams initialization problem we've discussed before.
A hacky way of doing this is via metaclasses. When an instance of a class is created, the metaclass __call__
method is invoked, which internally calls the class __new__
and class __init__
methods. We can create a custom metaclass for ModuleBase
that constructs the hparams
object before __init__
, and allows sub-metaclasses to append method calls after __init__
.
A diagram of instance creation is as follows, taken from this very good article that explains it all:
`
Thanks a lot. I think this modification is related to #41 I will think about it. |
Why is this PR related to "repeated-hparams initialization"? In particular, what's the |
It's because these two problems have similar root causes. The
Relation to repeated- The |
Thanks for explaining, and the possible solution. The solution can be a candidate we can apply at some point. Since it's a bit intricate, for now (when the issue has not widely occurred), let's just work around case by case. One of our interface design "principles" could to some extent (not completely) avoid the issue: put hyperparameters in It looks the |
Yes, we could leave this for the future. While the issue in the |
Requested by Zhiting's comments in PR in texar-tf
Make the interface of
XLNetEncoder
be consistent with other modules.