Mathematics in Deep Learning: CNNs, Transformers, Diffusion Models, and LLMs
Mathematics is the backbone of deep learning, enabling the development of sophisticated models that have revolutionized various fields, from computer vision to natural language processing. This article delves into the mathematical underpinnings of some of the most influential deep learning architectures: Convolutional Neural Networks (CNNs), Transformers, Diffusion Models, and Large Language Models (LLMs).
Convolutional Neural Networks (CNNs)
CNNs, introduced by LeCun et al. in 1989, are renowned for their prowess in image and vision-related tasks. The core of CNNs is the convolutional layer, which applies a set of learnable filters (kernels) to the input data. Mathematically, a convolution operation is defined as:
y[i, j, k] = ∑[m, n, p] x[i + m, j + n, k + p] * w[m, n, p], where:

xis the input volume,wis the filter,yis the output volume,i, j, kare the spatial and channel dimensions of the output,m, n, pare the spatial and channel dimensions of the filter.
CNNs also employ pooling layers for downsampling and fully connected layers for classification. The entire network is trained end-to-end using backpropagation and stochastic gradient descent (SGD).
Transformers
Introduced by Vaswani et al. in 2017, Transformers marked a paradigm shift in natural language processing with their self-attention mechanism. Given an input sequence X = [x₁, x₂, ..., xₙ], the self-attention mechanism computes attention scores for each pair of elements:
Attention(Q, K, V) = softmax(QKᵗ / √dₖ) * V, where:

Q, K, Vare queries, keys, and values obtained by multiplying the input embeddings with learned weight matrices,dₖis the dimension of keys,softmaxis applied along the last dimension.
Transformers stack multiple self-attention layers to create deep networks, and they use multi-head attention to attend to different positions simultaneously. They also employ position-wise feed-forward networks and add & norm layers for better performance.
Diffusion Models
Diffusion models, popularized by Ho et al. in 2020, generate high-quality samples by learning to reverse a gradual noising process. Given an input data point x₀, a forward diffusion process iteratively adds Gaussian noise to obtain x₁, x₂, ..., xₙ. The model then learns to reverse this process by predicting the noise at each timestep:
ε~ = ε(xₙ, t) - βₙ(xₙ - x₀), where:

ε~is the standard normal noise,βₙis the noise schedule,tis the timestep.
The model is trained using reweighted variant of the evidence lower bound (ELBO), and it can generate samples by running the denoising process for T timesteps.
Large Language Models (LLMs)
LLMs, such as those developed by teams like Meta and Google, are trained on vast amounts of text data to understand and generate human-like text. They are typically built upon transformer architectures, with increased model size and additional training techniques like instruction tuning and reinforcement learning from human feedback (RLHF). The mathematical foundation of LLMs lies in the transformer architecture discussed earlier, with additional components like language modeling loss and fine-tuning objectives.
Conclusion
Mathematics plays an indispensable role in deep learning, enabling the development of powerful models like CNNs, Transformers, Diffusion Models, and LLMs. By understanding the mathematical principles behind these architectures, researchers and practitioners can better design, analyze, and improve deep learning systems. As the field continues to evolve, so too will the mathematical tools and techniques that underpin it.





















