mila-iqia / blocks

A Theano framework for building and training neural networks
Other
1.16k stars 351 forks source link

Do we need ActivationDocumentation metaclass? #787

Open rizar opened 9 years ago

rizar commented 9 years ago

See https://github.com/mila-udem/blocks/blob/master/blocks/bricks/__init__.py#L432

It is justified by http://bugs.python.org/issue12773 in the code, but in fact docstrings are mutable for classes with non-trivial metaclasses. Taking that into account, I would rather use decorators for the purpose of adding docs as a more standard tool will more predictable consequences (e.g. one can only change the metaclass of any descendant of e.g. Tanh to subclasses of ActivationDocumentation, which I found inconvenient).

Switching to a decorator here would make the code look like

@add_activation_docs
class Tanh(Activation):
    @application(inputs=['input_'], outputs=['output'])
    def apply(self, input_):
        return tensor.tanh(input_)

that is one extra line for each activation.

janchorowski commented 9 years ago

That looks nicer.

rizar commented 9 years ago

"That" is with decorator or without?

janchorowski commented 9 years ago

With the decorator.

rizar commented 9 years ago

OK, then I will just put CCW label on that since it is not urgent.

rizar commented 9 years ago

Yet another argument in favour of a separate decorator is ability to inherit from Activation but without copying the docs, see #798