Bogdan Doicin
Bogdan Doicin

Reputation: 2416

What Does (x) After Calling a Function Mean?

I have the following Python code line:

x = layers.Dense(64, activation="relu")(x)

What does the (x) mean?

Upvotes: 1

Views: 205

Answers (1)

Andy
Andy

Reputation: 3170

It looks like you're specifically reading code written using the Keras library's Functional API (as opposed to the Sequential API). What this means is each neural network layer upon creation returns a function that must be called. To create a simple feed-forward neural network in this manner (with no skip-connections),

a. Create a layer that takes in your input. This yields a function that takes your input.
b. Create another layer and pass the previous layer in as input.
...
n. Create an output layer that takes the second-to-last layer as input.

Or

x_in = layers.Input(...)
x_1 = layers.Dense(...)(x_in)
x_2 = layers.Dense(...)(x_1)
x_out = layers.Dense(...)(x_2)

You don't need to assign each layer its own variable name, though, so the previous example could be rewritten as (and is commonly in tutorials as such):

x = layers.Input(...)
x = layers.Dense(...)(x)
x = layers.Dense(...)(x)
x = layers.Dense(...)(x)

Upvotes: 2

Related Questions