concept weight in category deep learning

This is an excerpt from Manning's book Deep Learning with Python, Second Edition.
The specification of what a layer does to its input data is stored in the layer’s weights, which in essence are a bunch of numbers. In technical terms, we’d say that the transformation implemented by a layer is parameterized by its weights (see figure 1.7). (Weights are also sometimes called the parameters of a layer.) In this context, learning means finding a set of values for the weights of all layers in a network, such that the network will correctly map example inputs to their associated targets. But here’s the thing: a deep neural network can contain tens of millions of parameters. Finding the correct value for all of them may seem like a daunting task, especially given that modifying the value of one parameter will affect the behavior of all the others!
Figure 1.9. The loss score is used as a feedback signal to adjust the weights.
![]()
The API through which you can leverage TensorFlow’s powerful automatic differentiation capabilities is the
GradientTape. It’s a Python scope that will “record” the tensor operations that run inside it, in the form of a computation graph (sometimes called a “tape”). This graph can then be used to retrieve the gradient of any output with respect to any variable or set of variables (instances of thetf.Variableclass). Atf.Variableis a specific kind of tensor mean to hold mutable state — for instance, the weights of a neural network are alwaystf.Variableinstances.

This is an excerpt from Manning's book Math and Architectures of Deep Learning.
What exactly happens during training? Answer: we iteratively process the input training data items. For each input item, we know the desired (aka target) output. On each iteration, we adjust the model weight values in a way that the output of the model function on that specific input item gets at least a little bit closer to the corresponding target output. For instance, suppose at a given iteration, the weight values are w0 = 20 and w1 = 10 and b = 50. On the input (hardness = 0.01, sharpness = 0.02), we get an output threat score y = 50.3 which is quite different from the desired y = −0.9. We will adjust the weights, for instance reduce the bias - so w0 = 20 and w1 = 10 and b = 40. The corresponding threat score y = 40.3 is still nowhere near the desired value, but it has moved closer. After doing this on many training data items, the weights would start approaching their ideal values. Note that how to identify the adjustments to the weight values is not discussed here. It needs somewhat deeper math and will be discussed later.
As stated above, this process of iteratively tuning weights is called training or learning. At the beginning of learning, the weights have random values, so the machine outputs often do not match desired outputs. But with time, more training iterations happen and the machine “learns” to generate the correct output. That is when the model is ready for deployment in real world. Given arbitrary input, the model will (hopefully) emit something close to the desired output during inferencing.
Come to think of it, that is probably how living brains work. They contain equivalents of mathematical models for various tasks. Here, the weights are the strengths of the connections (aka synapses) between the different neurons in the brain. In the beginning, the parameters are untuned, the brain repeatedly makes mistakes. E.g., a baby’s brain often makes mistake in identifying edible objects - anybody who has had a child will know what we are talking about. But each example tunes the parameters (eating green and white rectangular things with $ sign invites much scolding - should not eat them in future etc). Eventually this machine tunes its parameters to yield better results.
Consider a mythical city called Statsville. Suppose we pick up a random adult inhabitant of Statsville. What are the chances of this person’s height being above 6 ft? Below 3 ft? Between 5 ft. 5 inches and 6 ft? What are the chances of this person’s weight being between 50 and 70 Kgs[16]1? Above 100 Kgs? What are the probabilities of the person’s home exactly 6 Kms from the city center? What are the chances of the person’s weight being in the 50-70 Kg range and height in the 5 ft 5 inches to 6 ft range? What are the chances of the person’s weight being above 90 Kgs and his/her home being within 5 Kms of the city center?
Figure 5.2: Probability Distribution graph for weights of adults in Statsville, matching table 5.2. Event E1 ≡ X = 1 ⇒ weight in range S1, Event E2 ≡ X = 2 ⇒weight in range S2, Event E3 ≡ x = 3 ⇒ weight in range S3
![]()

This is an excerpt from Manning's book Deep Learning for Vision Systems.
In deep learning however, we do not need to manually extract features from the image. The network extracts features automatically while and learns their importance on the output by applying weights to its connections. You just feed the raw image to the network and while it passes through the network layers it identifies patterns within the image to create features. Neural networks can be thought of as feature extractors + classifiers that are end-to-end trainable as opposed to traditional ML models that use hand-crafted features.
Not all input features are equally important (or useful features). Each input feature (xi) is assigned its own weight (wi) that reflects its importance in the decision making process. In relatively easier terms, some inputs are made more important than others by giving them more weight so that they have a greater effect on the output. If the weight is high it amplifies the input signal and if the weight is low it diminishes the input. In common representations of neural networks, the weights are represented by lines or edges from the input node to the perceptron.
For example, if you are predicting a house price based on a set of features like size, neighborhood, and number_of_rooms, these are three inputs (x1, x2, and x3). Each of these inputs will have a different weight value that represents its effect on the final decision. So, if the size of the house has double the effect on the price than the neighborhood and the neighborhood is double the number of rooms, you will see the weights something like this 8, 4, and 2 respectively.
# load the weights that yielded the best validation accuracy model.load_weights('model.weights.best.hdf5')

This is an excerpt from Manning's book Deep Learning with PyTorch.
We are going to learn how to use the work of the best researchers in the field by downloading and running very interesting models that have already been trained on open, large-scale datasets. We can think of a pretrained neural network as similar to a program that takes inputs and generates outputs. The behavior of such a program is dictated by the architecture of the neural network and by the examples it saw during training, in terms of desired input-output pairs, or desired properties that the output should satisfy. Using an off-the-shelf model can be a quick way to jump-start a deep learning project, since it draws on expertise from the researchers who designed the model, as well as the computation time that went into training the weights.
Figure 5.7 The derivative of the loss function with respect to the weights
![]()

This is an excerpt from Manning's book Probabilistic Deep Learning: With Python, Keras and TensorFlow Probability.
Abbreviation / Term
Definition / Meaning
Aleatoric Uncertainty
Data inherent uncertainty which cannot be further reduced. For example, you can’t tell on which side a coin will land.
API
Application interface
Bayesian Mantra
The posterior is proportional to the likelihood times the prior.
BNN
Bayesian Neural Networks, NN with their weights being replaced by distributions. Solved with VI or MC-Dropout.
Bayesian Probabilistic Models
Probabilistic models that can state their epistemic uncertainty by characterizing all parameters of a distribution.
Bayesian View of Statistics
In the Bayesian view on statistics, the parameters
are not fixed but follow a distribution.
Bayesian Theorem
, this famous formula tells how to invert a conditional probability
Bayesian learning
, this formula tells you how to determine the posterior
from the likelihood
, the prior
and the marginal likelihood (aka evidence)
. It is a special form of the Bayesian theorem with
and
, with
being the parameters of a model and
the data.
Backpropagation
Method to efficiently calculate the gradients of the loss function w.r.t. the weights of a NN.
Bijectors
TFP package for invertible (bijective) functions needed for NF.
CIFAR-10
A popular benchmark data containing 60,000 32x32 color images of 10 classes.
CNN
Convolutional Neural Networks, NN especially suited for vision applications.
Computational Graph
A graph which encodes all calculations in a NN.
CPD
Conditional Probability Distribution. We also sloppily call the density
of an outcome y (e.g. the age of a person) given some input x (e.g. the image of a person) a CPD.
Cross Entropy
Another name for NLL in the case of classification tasks.
Deterministic Model
Non-Probabilistic Model, returning no distribution for the outcome but only one best guess.
Dropout
Dropout refers to randomly deleting nodes in a NN. Dropout during training yields typically NNs that show reduced overfitting. Performing Dropout also during test time (see MC dropout) is interpreted as an approximation of a BNN.
DL
Deep Learning
Extrapolation
Leaving the range of data with which a model was trained.
Epistemic Uncertainty
Uncertainty of the model caused by the uncertainty about the model parameters, which can in principle be reduced by providing more data.
fcNN
Fully connected neural networks.
GLOW
A certain CNN network based on NF which generates realistic looking faces.
ImageNet
A famous data set with 1 Million labeled images of 1000 classes.
Jacobian matrix
The Jacobian matrix of a multidimensional function or transformation in several variables is the matrix of all its first-order partial derivatives.
Jacobian Determinant
The determinant of the Jacobian matrix. It is used to calculate the change in volume happening in transformations, needed for NF.
Keras
Keras is a high-level neural networks API which we use in this book in conjunction with TensorFlow.
KL-Divergence
A kind measure for the distance between two PDFs.
Likelihood
The probability
that sampling from a density specified by a parameter value
produces the data.
Loss Function
A function which quantifies the badness of a model and which is optimized during the training of a DL model.
MAE
Mean Absolute Error. The MAE is a performance measure, which is computed as the mean of absolute values of the residuals. It is not sufficient to quantify the performance of probabilistic models (here the NLL should be used as performance measure).
MaxLike
Maximum Likelihood
MaxLike learning
A likelihood based method to determine the parameter values
of a model, for example the weight in a NN. The objective to maximize the likelihood of the observed data
. This corresponds to minimizing the NLL.
ML
Machine Learning
MC dropout
Monte Carlo Dropout refers to dropout during test time. A method that is interpreted as approximation to a BNN.
MNIST
More correctly the MNIST database of handwritten digits. A dataset of 60,000 28x28 greyscaled 10 classes (the digits 0-9).
MSE
Mean Squared Error. The MSE is a performance measure, which is computed as the average of the squared residuals. It is not sufficient to quantify the performance of For probabilistic models (here the NLL should be used as a performance measure).
NF
Normalizing Flow. NF is a NN based method to fit complex probability distributions.
NLL
Negative Log-Likelihood. The NLL is used as a loss function when fitting probabilistic models.
The NLL on the validation set is the optimal measure to quantify the prediction performance of a probabilistic model.NN
Neural Network
Observed outcome
The observed outcome or “
-value” which is measured for a certain instance i. In a probabilistic model, we aim to predict a CPD for y based on some features that characterize the instance i. Sometimes
is also bewilderingly called “true” value. We don’t like that expression since in the presence of aleatoric uncertainty there is no true outcome.
Probability density function. The PDF is also sometimes referred to as probability density distribution. See CPD for a conditional version.
PixelCNN++
A certain CNN model capturing the probability distribution of pixel values. The “++ version” uses advanced CPDs for performance.
Posterior
The distribution
of a parameter
after seeing the data D.
Posterior predictive distribution
The CPD
given the data D which results from a Bayesian probabilistic model.
Prediction Interval
Interval in which a certain fraction, typically 95%, of all data are expected.
Prior
The distribution
which is assigned to a model parameter
before seeing any data D.
Probabilistic Model
A model returning a distribution for the outcome.
Residuals
Differences between the the observed value
and the deterministic model output
(the expected value of the outcome).
RMSE
Root Mean Squared Error, the square root of the MSE.
RealNVP
A specific NF model called Real Non-Volume Preserving.
softmax
An activation function enforcing that the output of the neural network sums up to 1 and can be interpreted as a probability.
softplus
An activation function, which after it’s application ensures positive values
SGD
Stochastic Gradient Descent
Tensor
Multidimensional array, the main data structure in deep learning
TF
TensorFlow is a low-level library which is used in this book for DL.
The big lie of DL
The assumption P(Train)=P(Test), that the test data stems from the same distributions as the training data. In many DL / ML applications, this is assumed but often not true.
TFP
TensorFlow Probability add-on to TF facilitating probabilistic modeling of DL.
VGG16
A traditional CNN with a specific architecture that was on second rank of the imageNet competition in 2014. It is often used with weights that resulted after training on the imageNet data to extract feature from an image.
VI
Variational Inference is a method for which it can be shown that it yields an approximation to a BNN.
w.r.t.
with respect to
WaveNet
A specific NN model for text to speech.
ZIP
Zero Inflated Poisson a special distribution for count data taking care of an excess of the value 0.
After defining the model, it’s compiled. There the used loss and the optimization procedure needs to be specified. Here we use the loss function crossentropy, which is commonly used for classification and which quantifies how good the correct class is predicted. You’ll learn more about loss functions in chapter 4. Last but not least, we optimize the weights of the model by an iterative training process, which is called stochastic gradient descent (SGD) and which is discussed in chapter 3. The goal of the fitting process is to adapt the model weights so that the loss is minimized. The model weights are updated after each mini-batch, here containing 128 instances. One iteration over the complete training set is called an epoch, here we train for 400 epochs.
Listing 2.5 Edge lover CNN
model = Sequential() model.add(Convolution2D(1,(5,5),padding='same',input_shape=(pixel,pixel,1))) #A model.add(Activation('linear')) #B # take the max over all values in the activation map model.add(MaxPooling2D(pool_size=(pixel,pixel))) #C model.add(Flatten()) #D model.add(Dense(2)) #E model.add(Activation('softmax'))#F # compile model and initialize weights model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # train the model history=model.fit(X_train, Y_train, validation_data=(X_val,Y_val), batch_size=64, epochs=15, verbose=1, shuffle=True)
Each kernel can learn another set of weights, and so for each kernel, you get another activation map in the hidden layer (see figure 2.23). If the input has not only 1 but d channels, then the kernel also needs to have d channels to compute an activation map. For color images, you’ve d = 3 for (red, green, blue), and a valid kernel could be one that is active for a vertical edge in the green channel and horizontal edges in the blue and red channel. The kernel matrix again defines the weights for the weighted sum, which determines the input to the neuron in the respective position of the activation map.
Figure 2.23: Convolution of the input image with 6 different kernels results in 6 activation maps. If the input image has only one channel (a), then each kernel has also only one channel. If the input image has 3 channels (b), then each filter has also 3 channels.
![]()
![]()
Now let’s talk about analogies between in fcNN and CNNs. For each neuron in an fcNN, a new set of weights is learnt (the learning process is discussed in chapter 3) that combines the input of the former layer to a new value that can be seen as a feature of the image (see, for example, figure 2.8). In an fcNN, you can go deep by adding layers where all neurons of one layer are connected to all neurons in the next layer. In this sense, the number of kernel sets or activation maps in a CNN correspond to the number of neurons in one layer of an fcNN. If you want to go deep in a CNN, you need to add more convolutional layers. This means you learn kernels that are again applied to the stack of activation maps of the previous layers.
Figure 2.25 illustrates this principle. In that figure, you see a CNN with 3 convolutional layers. The convolution over a stack of activation maps isn’t different than the convolution with an input of several channels. In figure 2.23, only 6 activation maps are generated from a 3-channel input image. However, learning only 6 kernels isn’t common. A typical number to learn is 32 kernels in the first layer and even more kernels (often the number of kernels doubles when moving from layer to layer). To reduce the number of weights in a CNN, it’s also common to downsample the activation maps before doing the next round of convolution. This is often done by replacing a 2 x 2 patch of neurons in an activation map with the maximal activation. This step is called max pooling.

This is an excerpt from Manning's book Deep Learning with JavaScript: Neural networks in TensorFlow.js.
A layer of neural networks is similar to a mathematical function in that it is a mapping from an input value to an output value. However, neural network layers are different from pure mathematical functions in that they are generally stateful. In other words, they hold internal memory. A layer’s memory is captured in its weights. What are weights? They are simply a set of numerical values that belong to the layer and govern the details of how each input representation is transformed by the layer into an output representation. For example, the frequently used dense layer transforms its input data by multiplying it with a matrix and adding a vector to the result of the matrix multiplication. The matrix and the vector are the dense layer’s weights. When a neural network is trained through exposure to training data, the weights get altered systematically in a way that minimizes a certain value called the loss function, which we will cover in detail using concrete examples in chapters 2 and 3.
Figure 2.9. Illustrating the backpropagation algorithm through a simple linear model with only one updatable weight (v). Panel A: forward pass on the model—the loss value is calculated from the weight (v) and the inputs (x and y). Panel B: backward pass—the gradient of loss with respect to v is calculated step-by-step, from the loss to v.
![]()
Be able to interpret those weights and weigh them against your intuitions for what the weights should be.
The only difficult part is step 4: how can you determine which weights should be increased, which should be decreased, and by how much? We could simply guess and check, and only accept updates that actually reduce the loss. Such an algorithm might work for a simple problem like this one, but it would be very slow. For larger problems, when we are optimizing millions of weights, the likelihood of randomly selecting a good direction becomes vanishingly small. A much better approach is to take advantage of the fact that all operations used in the network are differentiable and to compute the gradient of the loss with regard to the network’s parameters.

This is an excerpt from Manning's book Grokking Deep Learning.
This also illuminates that parameters is a generic term, referring only to the set of numbers used to model a pattern (without any limitation on how those numbers are used). Counts are parameters. Weights are parameters. Normalized variants of counts or weights are parameters. Correlation coefficients can be parameters. The term refers to the set of numbers used to model a pattern. As it happens, deep learning is a class of parametric models. We won’t discuss nonparametric models further in this book, but they’re an interesting and powerful class of algorithm.
In chapter 3, you learned about the paradigm “predict, compare, learn,” and we dove deep into the first step: predict. In the process, you learned a myriad of things, including the major parts of neural networks (nodes and weights), how datasets fit into networks (matching the number of datapoints coming in at one time), and how to use a neural network to make a prediction.
With a set step_amount, unless the perfect weight is exactly n*step_amount away, the network will eventually overshoot by some number less than step_amount. When it does, it will then start alternating back and forth between each side of goal_prediction. Set step_amount to 0.2 to see this in action. If you set step_amount to 10, you’ll really break it. When I try this, I see the following output. It never remotely comes close to 0.8!
Error:0.3025 Prediction:0.25 Error:19.8025 Prediction:5.25 Error:0.3025 Prediction:0.25 Error:19.8025 Prediction:5.25 Error:0.3025 Prediction:0.25 .... .... repeating infinitely... !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":28}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":28}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":28}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":29}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":29}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":28}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":28}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":28}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":29}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":29}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":28}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":28}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":28}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":4}],[{\"line\":6,\"ch\":0},{\"line\":6,\"ch\":4}],[{\"line\":6,\"ch\":0},{\"line\":6,\"ch\":28}]]"} !@%STYLE%@!The real problem is that even though you know the correct direction to move weight, you don’t know the correct amount. Instead, you pick a fixed one at random (step_amount). Furthermore, this amount has nothing to do with error. Whether error is big or tiny, step_amount is the same. So, hot and cold learning is kind of a bummer. It’s inefficient because you predict three times for each weight update, and step_amount is arbitrary, which can prevent you from learning the correct weight value.
What if you had a way to compute both direction and amount for each weight without having to repeatedly make predictions?
The primary difference between gradient descent and this implementation is the new variable delta. It’s the raw amount that the node was too high or too low. Instead of computing direction_and_amount directly, you first calculate how much you want the output node to be different. Only then do you compute direction_and_amount to change weight (in step 4, now renamed weight_delta):
![]()
weight_delta is a measure of how much a weight caused the network to miss. You calculate it by multiplying the weight’s output node delta by the weight’s input. Thus, you create each weight_delta by scaling its output node delta by the weight’s input. This accounts for the three aforementioned properties of direction_and_amount: scaling, negative reversal, and stopping.
![]()
You multiply weight_delta by a small number alpha before using it to update weight. This lets you control how fast the network learns. If it learns too fast, it can update weights too aggressively and overshoot. (More on this later.) Note that the weight update made the same change (small increase) as hot and cold learning.