Skip to main content
8 votes

How is this Pytorch expression equivalent to the KL divergence?

This is the analytical form of the KL divergence between two multivariate Gaussian densities with diagonal covariance matrices (i.e. we assume independence). More precisely, it's the KL divergence ...
nbro's user avatar
  • 40.9k
8 votes
Accepted

While fine-tuning a decoder only LLM like LLaMA on chat dataset, what kind of padding should one use?

I got an answer to this question, probably a correct explanation. In decoder-only model architectures, the output of the model is a continuation of the model input. For example, input: I love apple [...
尹雅博's user avatar
7 votes
Accepted

Transformers: How to use the target mask properly?

The main issue during training is that you haven't right-shifted the input of the decoder, which is probably why you set the diagonals of mask to -inf (when it ...
user3667125's user avatar
  • 1,600
7 votes

Is there any difference between affine transformation and linear transformation?

In linear algebra, a linear transformation (aka linear map or linear transform) $f: \mathcal{V} \rightarrow \mathcal{W}$ is a function that satisfies the following two conditions $f(u + v)=f(u)+f(v)$ ...
nbro's user avatar
  • 40.9k
6 votes
Accepted

How is this Pytorch expression equivalent to the KL divergence?

The code is correct. Since OP asked for a proof, one follows. The usage in the code is straightforward if you observe that the authors are using the symbols unconventionally: ...
Sycorax's user avatar
  • 473
6 votes
Accepted

When should you not use the bias in a layer?

The most usual case of bias=False is in layers before/after Batch Normalization with no activators in between. The BatchNorm layer will re-center the data anyway, ...
Kostya's user avatar
  • 2,534
6 votes
Accepted

What exactly is an XPU?

XPU is a device abstraction for Intel heterogeneous computation architectures, which can be mapped to CPU, GPU, FPGA and other accelerators. The "X" from XPU is just like a variable, like in ...
JVGD's user avatar
  • 1,138
5 votes
Accepted

Why is the number of output channels 16 in the hidden layer of this CNN?

I understand your question as: "How did the author select the number of neurons in their hidden layer?" The number of neurons in the hidden layer is how you can control the complexity of the function ...
JahKnows's user avatar
  • 470
5 votes

What does 'input planes' mean in the phrase 'input signal/image composed of several input planes'?

Yes, it is a bit misleading. What it really means is input channels, so it would be: nn.Conv2d: Applies a 2D convolution over an input signal composed of several input channels. So, why don't just use ...
JVGD's user avatar
  • 1,138
5 votes

What is the Intermediate (dense) layer in between attention-output and encoder-output dense layers within transformer block in PyTorch implementation?

Feedforward layer is an important part of the transformer architecture. Transformer architecture, in addition to the self-attention layer, that aggregates ...
spiridon_the_sun_rotator's user avatar
5 votes

How can the input order of pairs into a neural network not matter (i.e. symmetry)?

The problem you're describing is related to (if not a subset of) Shift Invariance. Shift invariance refers to any geometric translation of an input, but concatenation of a pair of tenors in 2 ...
Edoardo Guerriero's user avatar
4 votes
Accepted

Is there a reason to use TensorFlow over PyTorch for research purposes?

In the past, I have used TensorFlow (1 and 2), Keras and PyTorch, so I will give an answer based on my experience. Currently, I use TF 2 and Keras (the version shipped with TF 2). In my (but not only)...
nbro's user avatar
  • 40.9k
4 votes

Is there any difference between affine transformation and linear transformation?

The fact is you can always express an affine transformation as a linear transformation (more convenient because it is just a matrix/dot product). For instance, given an input $\textbf{x}=[x_1, ..., ...
y-prudent's user avatar
4 votes

What exactly happens in gradient clipping by norm?

Gradient clipping is a technique that tackles exploding gradients. The idea of gradient clipping is very simple: If the gradient gets too large, we rescale it to keep it small. More precisely, $$ \...
Archana David's user avatar
4 votes
Accepted

Why in Multi-Head Attention implementation should we use $3$ linear layers for Q, K, V instead of $3 * h$ layers?

It is just an optimization technique. If you have a vector $x$ of size $d$ and you want to multiply with $n$ different matrices $W_i$ of shape $d \times d_k$, then you could simply stack these ...
pi-tau's user avatar
  • 815
3 votes
Accepted

Should the policy parameters be updated at each time step or at the end of the episode in REINFORCE?

The essence of your observation is that Sutton's version of REINFORCE is taking into consideration all of the trajectory to compute the returns, while in the pytorch version only the future is taken ...
Dimitris Monroe's user avatar
3 votes
Accepted

What are the differences between TensorFlow and PyTorch?

TensorFlow was developed by Google and is based on Theano (Python library), while Facebook developed PyTorch using the Torch library. Both frames are useful and have a great community behind them. ...
Hiren Namera's user avatar
3 votes
Accepted

Are the training loss and validation loss plotted per sample or per batch?

You want to compute the mean loss over all batches. What you need to do is to divide the sum of batch losses with the number of batches! In your case: You have a training set of $21700$ samples and ...
Djib2011's user avatar
  • 3,193
3 votes
Accepted

Why is the policy loss the mean of $-Q(s, \mu(s))$ in the DDPG algorithm?

This is not quite the loss that is stated in the paper. For standard policy gradient methods the objective is to maximise $v_{\pi_\theta}(s_0)$ -- note that this is analogous to minimising $-v_{\pi_\...
David's user avatar
  • 4,920
3 votes
Accepted

Can TensorFlow, PyTorch, and other mainstream ML frameworks be used for research-grade work in AI?

Your statement that researchers build their network from the ground-up using C++ or some other low level library couldn't be further from the truth. You could take a look at this analysis showing the ...
Djib2011's user avatar
  • 3,193
3 votes
Accepted

Why do we multipy context_size with embedding_dim? (PyTorch)

An n-gram language model is a language model trained with n context words. This means you're not feeding the model a single word but n. This is why the dimension of the input layer is "...
Edoardo Guerriero's user avatar
3 votes
Accepted

Not able to understand Pytorch Tensor (Weight & Biases) Size for Linear Regression

The size of the parameters tensor is depended on what type of layer that you want to build. Convolutional, fully connected, attention or even custom layer, each layer has a difference in the way it ...
CuCaRot's user avatar
  • 912
3 votes
Accepted

When exactly does the split into different heads in Multi-Head-Attention occur?

The queries, keys and values are calculated then chunked so that each chunk depends on (is a linear combination of) all values of the input embedding. As for understanding an implementation, I didn't ...
Tom Huntington's user avatar
3 votes

How to generate new data given a trained VAE - sample from the learned latent space or from multivariate Gaussian?

Few more clarifications. While the correct thing to do is draw from the prior, we have no guarantees that the aggregated posterior will cover the prior. Think of the aggregated posterior as the ...
sfotiadis's user avatar
  • 291
3 votes
Accepted

How can I use larger input images when using a pre-trained CNN without resizing?

TL;DR: It's definitely worth trying to benefit from the learned features from the ResNet. As it's made of mainly pretrained convolutional layers with pooling, adding new resizing layers upfront is ...
James Ashford's user avatar
3 votes
Accepted

Is it possible to write/build an AI model without using Frameworks?

In short : YES, you can build AI models without a framework Now, onto the details: Before discussing "why", let's look at what is an ML framework: Simply put, an ML framework is a ...
Jay's user avatar
  • 46
3 votes

What is actually being saved in the file when you save a model? For example a Tensorflow SavedModel file

Answer to Question 1 TensorFlow's documentation provides the following information on what is saved: The model config, weights, and optimizer are included in the SavedModel. Additionally, for every ...
Brian O'Donnell's user avatar
2 votes
Accepted

Heavy loss and inaccurate answer in pytorch

There are a few things you could do to improve this NN, but are probably worth covering in different questions. Your main problem though is that you forgot to reset the gradient after each training ...
Neil Slater's user avatar
  • 32.7k
2 votes

Super Resolution CNN generates black dots on output images

This is a while ago, but still this problem might occur to someone. I encountered the same problem and found that the reason was how the resulting tensors are transformed to images. It seams that ...
Ingmar Ludwig's user avatar
2 votes
Accepted

Is there ever a need to combine deep learning frameworks? (Eg. TensorFlow & Torch)?

In the time since I asked this question, I have been able to combine Tensorflow and Chainer considerably well. That being said, one should try to avoid combining deep learning frameworks if one can ...
Jaden Travnik's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible