liveBook · Manning

Linear layer

As explained in Build AI Drug Discovery Pipelines

A linear layer is a neural-network layer that applies an affine transformation to its input using a weight matrix and bias vector.

A linear layer transforms an input vector using a learnable weight matrix and bias vector: xWᵀ + b. Also called a fully connected or dense layer, it connects every output neuron to every input neuron. In a drug-discovery model, such layers can turn a molecular representation into features used to predict a molecule’s properties. section 8.2.1 section 8.2.2

In PyTorch, nn.Linear(input_size, 512) maps input_size features to 512 outputs. Its weight matrix has shape (512, input_size), and its bias has 512 values. The output size of one layer must match the input size of the next. Weights and biases are learned during training. section 8.2.2

Predicting kinase binding

A feedforward network takes a molecular bit vector, with 2048 features by default, through linear layers sized 2048 → 512 → 256 → 1. ReLU follows each hidden linear layer to introduce nonlinearity, and dropout provides regularization. The final layer produces a single prediction. section 8.2.2

Listing 8.6 Kinase Binder Neural Network Architecture
class KinaseBinderNN(nn.Module):
    def __init__(self, input_size=2048):
        super(KinaseBinderNN, self).__init__()
        self.fc1 = nn.Linear(input_size, 512)
        self.fc2 = nn.Linear(512, 256)
        self.fc3 = nn.Linear(256, 1)
        self.relu = nn.ReLU()
        self.dropout = nn.Dropout(0.2)
        
    def forward(self, x):
        x = self.dropout(self.relu(self.fc1(x)))
        x = self.dropout(self.relu(self.fc2(x)))
        x = self.fc3(x)
        return x
 

Inspect the layer definitions and forward pass, including where ReLU and dropout are applied. section 8.2.2

Predicting drug-target affinity

After graph pooling, two linear layers transform a 312-dimensional molecular representation through 1024 dimensions into a 128-dimensional embedding. A separate protein embedding is combined with it; further linear layers then map the combined 256 features through 1024 and 512 dimensions to one unbounded affinity prediction. section 11.5.2 section 11.5.3

Layer width is a design trade-off: more neurons can increase learning capacity, but also increase computational cost and the risk of overfitting. section 8.2.1

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains the affine operation, parameter dimensions, layer connectivity, and forward-pass composition in worked PyTorch architectures.
Examples
Illustrates kinase-binding prediction from molecular bit vectors and drug-target affinity prediction from pooled graph representations.
What you can do after
Apply it via PyTorch nn.Linear to assemble dimension-matched layers for molecular prediction.
How it connects
Connects linear layers to feedforward networks, ReLU, dropout, graph pooling, and embeddings.

Also explained in

Compare how 17 books explain linear layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.