Overview

8 Introduction to Deep Learning

This chapter introduces deep learning as a transition from earlier, more traditional machine learning methods toward neural network-based approaches in drug discovery. It frames the shift around practical applications in both ligand-based and structure-based screening, with PyTorch serving as the main framework for building, training, and evaluating models. The chapter’s goal is not to provide exhaustive PyTorch coverage, but to give a working foundation for applied deep learning in realistic discovery workflows.

A central example is EGFR, a kinase target of major interest in oncology because its dysregulation is often tied to cancer. The text explains why kinases are attractive yet difficult targets: they are biologically important, data-rich, and challenging to model because of conserved ATP-binding sites that can lead to off-target effects. To build a prediction model, the chapter uses curated bioactivity data, converts molecules into Morgan fingerprints, splits the data with scaffold-based splitting to better test generalization, and trains a small neural network to predict pIC50 values.

Beyond the application, the chapter explains the mechanics that make neural networks work in PyTorch. It introduces tensors, computational graphs, automatic differentiation, backpropagation, activation functions, dropout, optimizers, and learning-rate scheduling, showing how these pieces interact during the forward and backward passes. The chapter also emphasizes evaluation through test error and enrichment-based screening metrics, helping readers understand not only how to train a model, but also how to judge whether it is useful for prioritizing compounds in virtual screening.

Roadmap for this chapter, starting with the high-level implementation of a PyTorch model and followed by detailed coverage of the underlying mechanics that govern our implementation.
Map of human protein kinases, i.e., the Manning kinome tree, clustered based on sequence similarity into eight major groups [3].
Outline the topics we’ll cover as we implement, train, and evaluate our first PyTorch model.
Relationship between the predicted pIC50 values of the test set against their true pIC50 values.
Enrichment plot for our model. The closer the model’s curve to the optimal enrichment line, the better the model’s performance.
Example of a computational graph at a high level of abstraction.
Computational graph for logistic regression. The input node represents the input data fed into the graph. Learnable parameter nodes for the weights and bias are used in conjunction with the input data for intermediate computations, ending with a prediction, 𝑎, that is compared to the true class label, 𝑦, to compute the loss.
Prior to backpropagation, our model makes a prediction, and this prediction is compared to the actual target to compete the error. To figure out which parts of the graph contributed most to the error, we start from the end (the error) and work backwards through the solution process. The error is propagated backwards through the network and the contribution of each parameter (weight and bias) to the error is calculated. These parameters are adjusted slightly to reduce the error.
We generalize the computational graph from figure 8.7 to support an arbitrary number of inputs. We also simplify the computational graph’s representation of the trainable parameters.
A neural network can be composed of artificial neurons across an arbitrary number of hidden layers (i.e., network depth) and number of neurons per layer (i.e., network width). Each neuron can be decomposed into a computational graph similar to what we visualized in previous figures, which we then chain to form the larger, more complex network.
Comparison of activation functions: sigmoid (i.e., logistic), hyperbolic tangent, rectified linear unit (ReLU), and step function. In the earlier computational graphs of a logistic classifier, we used the sigmoid or logistic activation function. In our modeling approach, we switched to using the ReLU activation function.
In this example, a dropout rate of 0.5 has been set, resulting in 50% of hidden neurons being dropped in a given training iteration.
Logging the train and validation loss with each epoch of training. The validation loss saturates before 50 epochs, which informs further hyperparameter tweaking (e.g., cut down the number of epochs or use early stopping, adjust the learning rate or scheduler, etc.).

Summary

  • Deep learning is a powerful tool in various chemical domains, including drug discovery, materials science, and quantum chemistry. By leveraging neural networks capable of learning complex patterns from vast amounts of data, deep learning algorithms uncover insights that were previously unattainable through traditional computational methods.
  • Protein kinases are one of the main protein families targeted in drug design, especially for cancer and inflammatory diseases. As of 2024, there are around 80 approved small molecule protein kinase inhibitors, with an additional 150 in clinical testing. Despite this success, the targets of the FDA-approved kinase inhibitors represent a small percentage of the entire kinase protein family – a large portion of the kinome is underexplored. From the perspective of “the glass Is half full”, the underexplored kinome presents many opportunities for development of novel drugs.
  • Tensors are the fundamental data structure in PyTorch. They are multi-dimensional arrays similar to NumPy arrays but with additional features that make them suitable for deep learning computations. Tensors can be created on CPU or GPU (for accelerated computations), support a wide range of mathematical operations, and encode the inputs, outputs, and parameters of a model.
  • Our basic PyTorch workflow involved preparing the data by converting inputs into numerical representations to be ingested by our neural network as tensors and preparing the model architecture by specifying its structure in PyTorch. We then fit the model to the data, evaluated the model’s predictions on test data against actual values, reviewed modifications to the architecture (e.g., ReLU activation function, Adam optimizer, learning rate scheduling, regularization via dropout) to improve the model, and saved our final model for later reuse.
  • A common goal in any ranking or screening process, e.g., virtual screening, is to prioritize the identification of a small number of the most relevant (active) compounds as quickly as possible, rather than screening through the entire data set. Hence, we use the model to score compounds and, ideally, the most likely actives appear near the top of the ranked list. This early recognition problem encapsulates our desire that we find a large portion of active compounds quickly, i.e., after screening only a small percentage of the dataset, to accelerate hit discovery. The enrichment factor (EF) is a key metric in evaluating how well a method satisfies the early recognition problem.
  • A computational graph is a representation of a mathematical expressions as a directed graph. In the computational graph, each node represents an operation or variable and each edge represents the flow of data between operations. Computation graphs are fundamental to how modern deep learning frameworks like PyTorch work. They allow for efficient computation and, crucially, for automatic differentiation, which is key to backpropagating gradient computations and training neural networks.
  • Our logistic regression model is analogous to a single-layer neural network composed of only a single neuron with a logistic, or sigmoid, activation function. We chain multiple neurons together, with the output of one neuron feeding into a successive neuron, to construct neural networks of arbitrary width and depth for improved feature extraction. The composition of the neural network’s number of layers and neurons is referred to as its architecture. A neural network’s architecture incorporates three types of layers – one input layer with a node for each input, one or more hidden layers full of artificial neurons, and one output layer representing the network’s output.

FAQ

What is the main goal of Chapter 8, “Introduction to Deep Learning”?The chapter introduces deep learning for drug discovery, moving from earlier Scikit-Learn workflows to PyTorch-based neural networks. It focuses on ligand-based virtual screening for EGFR pIC50 prediction, then explains the neural network theory and PyTorch mechanics behind the model.
Why is EGFR an important target in drug discovery?EGFR is a transmembrane protein involved in controlling cell growth and division. Mutations or overexpression of EGFR are linked to several cancers, making it a valuable target for developing tyrosine kinase inhibitors and other anticancer therapies.
What is pIC50 and why is it used instead of IC50?pIC50 is the negative logarithm of IC50. It is easier to model because it compresses the scale, reduces skew from outliers, and typically falls within a more convenient range for regression tasks. Higher pIC50 means greater potency.
How does the chapter prepare molecular data for a PyTorch model?The chapter converts SMILES strings into Morgan fingerprints, then wraps them and the corresponding pIC50 values in a custom PyTorch Dataset. DataLoader objects are then used to batch, shuffle, and iterate over the data efficiently.
Why does the chapter use scaffold splitting instead of a random split?Scaffold splitting keeps molecules with the same structural scaffold in the same split, making the test set more challenging and more realistic for generalization. It helps avoid overly optimistic performance estimates caused by similar compounds appearing in both train and test sets.
What is a tensor in PyTorch?A tensor is PyTorch’s fundamental data structure: a multi-dimensional array used to store inputs, outputs, and model parameters. Tensors support CPU/GPU computation and many mathematical operations needed for deep learning.
What is a computational graph in neural networks?A computational graph is a directed graph representation of a mathematical expression, where nodes are operations or variables and edges represent data flow. PyTorch uses this graph to compute gradients automatically during backpropagation.
What do backpropagation and autograd do?Backpropagation is the process of computing gradients by moving backward through the computational graph. Autograd is PyTorch’s automatic differentiation engine that records tensor operations and calculates these gradients for model parameters when you call backward().
Why does the model use ReLU and dropout?ReLU helps reduce vanishing gradient problems because it does not saturate for positive inputs, making training more stable. Dropout randomly zeroes a fraction of hidden units during training to reduce overfitting and improve generalization.
How is the model trained and evaluated in the chapter?The model is trained with MSELoss, Adam optimization, and a ReduceLROnPlateau learning-rate scheduler. Training uses epochs with validation after each epoch, and final evaluation on the test set reports test loss, MSE, and MAE before saving the model with torch.save().

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build AI Drug Discovery Pipelines ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build AI Drug Discovery Pipelines ebook for free