5 ms·
This article describes positional encodings based on several sine waves with different frequencies, but I've also seen positional "embeddings" used, where the p
by Buttons840 4y ago
This article describes positional encodings based on several sine waves with different frequencies, but I've also seen positional "embeddings" used, where the position (the position is an integer value) is used to select an differentiable embedding from an embedding table. Thus, the model learns its own positional encoding. Does anyone know how these compare?
I've also wondered why we add the positional encoding to the value, rather than concatenating them?
Also, the terms encoding, embedding, projection, and others are all starting to sound the same to me. I'm not sure exactly what the difference is. Linear projections start to look like embeddings start to look like encodings start to look like projections, etc. I guess that's just the nature of linear algebra? It's all the same? The data is the computation, and the computation is the data. Numbers in, numbers out, and if the wrong numbers come out then God help you.
I digress. Is there a distinction between encoding, embedding, and projection I should be aware of?
I recently read in "The Little Learner" book that finding the right parameters is learning. That's the point. Everything we do in deep learning is focused on choosing the right sequence of numbers and we call those numbers parameters. Every parameter has a specific role in our model. Parameters are our choice, those are the nobs that we (as a personified machine learning algorithm) get to adjust. Ever since then the word "parameters" has been much more meaningful to me. I'm hoping for similar clarity with these other words.
- giovannibonetti 4y ago> I recently read in "The Little Learner" book that finding the right parameters is learning. That's the point. Everything we do in deep learning is focused on choosing the right sequence of numbers and we call those numbers parameters. Every parameter has a specific role in our model. Parameters are our choice, those are the nobs that we (as a personified machine learning algorithm) get to adjust. Be careful not to mistake parameters for hyperparameters. - Parameters are the result of the training phase, as you mentioned. They start with random values and are discovered by the training algorithm; - Hyperparameters, on the other hand, are the knobs you tweak to make the training process arrive at the "right" parameters. You can think of them as meta-parameters; Also, it is important to think on the ML architecture - transformers, neural networks, random forests and so on - as the parameters change completely depending on which one you're using.
- Buttons840 4y agoYes, hyper-parameters are parameters about the parameters. Parameters we get to choose which control the parameters that the learning algorithm chooses. The other set of data the book called "arguments", which is the term they use to describe the data you are training on. That seems like an unnecessarily confusing term, and I haven't heard it anywhere else. I didn't learn anything truly new in all this, but it helped me sort my own thoughts to realize there is data, parameters, and hyperparameters. Data comes from the world and we cannot change it. Parameters are chosen by us indirectly through the learning algorithm, they are the most important outcome of successful learning. Hyperparameters are chosen by us directly and control the model and learning algorithm, and the resulting parameters.
- whoateallthepy 4y agoThis is a great set of comments/questions! To try and answer this a bit briefly: The input string is tokenized into a sequence of token indices (integers) as the first step of processing the input. For example, "Hello World" is tokenized to: [15496, 2159] The first step in a transformer network is to embed the tokens. Each token index is mapped to a (learned or fixed) embedding (a vector of floats) via the embeddings table. The Embeddings module from PyTorch is commonly used. After mapping, the matrix of embeddings will look something like: [[-0.147, 2.861, ..., -0.447], [-0.517, -0.698, ..., -0.558]] where the number of columns is the model dimension. A single transformer block takes a matrix of embeddings and transforms them to a matrix of identical dimensions. An important property of the block is that if you reorder the rows of the matrix (which can be done by reordering the input tokens), the output will be reordered but otherwise identical too. (The formal name for this is permutation equivariance). In problems related to language it seems inappropriate to have the order of tokens not matter, so to solve for this we need to adjust the embeddings of the tokens initially based on their position. There are a few common ways you might see this done, but they broadly work by assigning fixed or learned embeddings to each position in the input token sequence. These embeddings can be added to our matrix above so that the first row gets the embedding for the first position added to it, the second row gets the embedding for the second position, and so on. Now if the tokens are reordered, the combined embedding matrix will not be the same. Alternatively, these embeddings can be concatenated horizontally to our matrix: this guarantees the positional information is kept entirely separate from the linguistic (at the cost of having a larger model dimension). I put together this repository at the end of last year to better help visualize the internals of a transformer block when applied to a toy problem: https://github.com/rstebbing/workshop/tree/main/experiments/transformer_sequence_classification https://github.com/rstebbing/workshop/tree/main/experiments/.... It is not super long, and the point is to try and better distinguish between the quantities you referred to by seeing them (which is possible when embeddings are in a low dimension). I hope this helps!
- dist-epoch 4y ago> The input string is tokenized into a sequence of token indices (integers) How is this tokenization done? Sometimes a single word can be two tokens. My understanding is that the token indices are also learned, but by whom? The same transformer? Another neural network?
- Silverback_VII 4y agoAlso, the terms encoding, embedding, projection, and others are all starting to sound the same to me. Well, projection is used to create the embedding with which the symbol is encoded. It greatly reduces computational cost as the encoding carries already a lot of information.
- ralusek 4y agoWhat I don't understand about positional encoding is why use sine waves at all? Sine waves have a weird property of "accelerating" and "decelerating," such that the distance between two points that are linearly the same distance apart in a sentence would result in two very different positional encodings relative to one another, just arbitrarily dependent on where they were in the curve. I'm sure this is somewhat counteracted by the fact that you have lots of these sine waves offset and at different frequencies, but it still seems like an unnecessary feature. Wouldn't the positional encoding be better served by encoding to positions on a triangle waveform like this: https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Waveforms.svg/2560px-Waveforms.svg.png https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Wa... Could still do all of the same tricks of overlaying waves of different frequencies, but let the words be much more linearly related to one another. I suspect the function to plot to a wave like this is something like a modulus operation, where you adjust the modulus to produce different frequencies. And a normal modulus would get you something like the "sawtooth" graph, but if you did it so that you could determine if you were in an even or an odd period of the modulus, then you 1 - v the even ones and you'd get something like a triangle wave.
- ralusek 4y agoI'm sure there's an even better positional encoding that can get around the ugly feature that both triangle and sine waves have of having distinct points where they "change direction." I suspect there's a way around this by sampling values from a 2 dimensional space while moving in a circle, something like that.
- zwaps 4y agoYou might be misunderstanding the use of sin-cos in early positional embeddings. The waves are shifted such that each position gets a unique positional encoding. These encodings are not relative in distance to other positions, they are at best ordinal. They are meant to provide the same flexibility for the model as absolute positional encoding that are learned (so, position=2 always gets the same encoding) - which is what they achieve. The matter of learning about distances between positions is left up to the later stages of the model. This differs from the much more modern approach of relative positional embeddings, for instance Alibi or Rotary Embeddings. These I think fit your intuition much better, as they seek to encode relative distances between tokens correctly.