2

I know that 'X' on right-hand side is the input before you applied dropout. Now when you say Dropout(0.5)(X), it means that you are randomly making the activation of 50% of the neurons in the input to zero.

This line Dropout(0.5) means which are making a new object of class Dropout and passing 0.5 in its constructor. But appending X at the end of it? What does this mean in Python Syntax?

Rahul
  • 10,830
  • 4
  • 53
  • 88

1 Answers1

6

There are multiple ways that this code can work, 2 come into my mind right now:

Using the built in __call__ function of classes

>>> class MyClass:
...     def __init__(self, name):
...             self.name = name
...     def __call__(self, word):
...             print(self.name, 'says', word)
...
>>> MyClass('Tom')('hello')
Tom says hello

A function returning a function

>>> def add(a):
...     def f2(b):
...             print(a+b)
...     return f2
...
>>> add(1)(2)
3

I hope this helps

Jonathan R
  • 3,652
  • 3
  • 22
  • 40
  • After having a look in the source ([Github Keras Dropout](https://github.com/keras-team/keras/blob/7a39b6c62d43c25472b2c2476bd2a8983ae4f682/keras/layers/core.py#L119)) it turns out that actually the `__call__`-approach has been used in this case. Thanks for sharing both possible approaches! – Luke Feb 20 '20 at 13:14