Skip to content

Dense

Dense is the standard fully connected layer used in most typical neural networks.

Each output feature is computed as the weighted sum of all input features, followed by a bias term.

Bases: Module

A fully connected layer.

Applies the affine transformation

y = xW + b

to the input tensor.

Parameters:

Name Type Description Default
in_shape int

Number of input features.

required
out_shape int

Number of output features.

required

Shapes

Input:
    (N, in_features)

Output:
    (N, out_features)
Example

layer = ntk.Dense(784, 128)

y = layer(x)

Example

import neuraltoolkit as ntk
import numpy as np

sample_count = 50
input_features = 10

x = ntk.Tensor(
    np.random.rand(sample_count, input_features)
)

layer = ntk.Dense(
    in_shape=input_features,
    out_shape=4
)

y = layer(x)