0

I am working through a course on deep learning with Python and ran into this line:

hidden = Dense(2)(visible)

What does the second parameter do? Is this a python language feature I've missed?

2 Answers 2

2

I remember asking the same thing when I was learning Keras.

hidden = Dense(2)(visible)

You can rewrite this in a more verbose way as below:

dense_layer = Dense(2)
hidden = dense_layer(visible)

As you can see from the above, the first line creates an instance of the Dense layer, and then you can call that layer on a tensor. This adds the Dense operation to a graph of operations.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah. I was wondering if it returned a function. Thank you.
It does not return a function. It creates a class, and that class implements the __call__ method, which allows you to call it like a function. Also if this answered your question, please accept it by clicking the green check mark.
0

Visible is not a language specific feature or something. Your code should not have only this line but before that you probably define a variable named visible like below.

from keras.layers import Input
from keras.layers import Dense
visible = Input(shape=(2,))
hidden = Dense(2)(visible)

Here are some examples:

source1 source2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.