jdbennet
jdbennet

Reputation: 3

Keras function parameters not valid Python?

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?

Upvotes: 0

Views: 39

Answers (2)

jkr
jkr

Reputation: 19310

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.

Upvotes: 2

ismetguzelgun
ismetguzelgun

Reputation: 1105

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

Upvotes: 0

Related Questions