Live data from Hacker News

Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

news.ycombinator.com

111–120 of 240 posts

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#111
post #44

"Transformers" and "Attention is All You Need" refer to an important development in machine learning and artificial intelligence, particularly in the field of natural language processing (NLP). I'll try to explain them in a simple way. Think of a conversation you had with a friend. While they were talking, you were probably not just listening to the words they were saying right now, but also remembering what they sai…

Did you use GPT to write this? (Not a bad thing! It's a decent answer)

I copy pasted the attention is all you need paper into ChatGPT4 and gave it the prompt "Explain like I'm 5 years old".

The Transformer is a new type of computer program that helps translate languages and understand sentences. It works by paying attention to different parts of a sentence at the same time, instead of looking at one word after another like older programs. This makes it faster and better at understanding complicated sentences. It has been tested on translating English to German and English to French and did a really good job.

(Edit)

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#112

Earlier quoted context omitted.

Yeah sorry, it still requires math and probably some exposure to ML basics.

I think one hole in the description for simplicity is that "differentiable" it's not an adjective that applies to hash tables. Differentiable relative to what? What is (x) in the d(hashtable)/d(x) equation?

I think it applies because lookups can be done by multiplying one-hot vectors (or masks) with matrices; this is roughly analogous to what happens when we multiply Q with K^T in a self-attention head.

Read this: https://e2eml.school/transformers.html#table_lookup

And then read: https://e2eml.school/transformers.html#attention

Matrix multiplication is differentiable as it is continuous. Therefore you can calculate partial derivatives of these operations. The ability to do that is what allows gradient descent optimization via the chain rule.

  > Differentiable relative to what?
  > What is (x) in the d(hashtable)/d(x) equation?
I think the derivative we actually care about is `∂L/∂(hashtable-lookup)` but here the `hashtable-lookup` is actually the matrix multiplication mentioned above. We want to know how much the "loss" (or error) changes with respect to each of our "lookups". Knowing how each of our "lookups" causes our model to err from the output we expect, allows us to optimise it.

Note: it's not really a "lookup" in the normal sense of the word. Hashtable lookups are discontinuous since we either have a value for a particular key or we do not. Our matrix multiplication is sort of like a fuzzy, probabilistic, continuous form of lookup in which nearby keys get partially activated based on their similarity to the query, and in which a small change in this query causes continous changes to the keys produced.

As far as my understanding of the self-attention equation (e.g. `softmax(QK^T / sqrt(d_k))V`) goes, its actually quite important that we get this fuzzy output in which lots of keys get partially activated for a particular query. If it only picked the maximum similarity and ignored the rest, there would be less information propagating through the network and it'd be harder for the network to learn relationships/interactions between inputs. This is why we scale `QK^T` by `sqrt(d_k)` in order to pass a tighter range of values into the `softmax()` function (which importantly generates probabilities that sum to 1, but contains exponentials which give it a tendency to over-emphasize the maximum value and ignore other values if they are too far apart).

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#113

The "Attention is All You Need" paper introduced a new way for AI to read and understand language, much like how we might read a comic book. As you read each panel of a comic book, you don't just look at the words in the speech bubbles, but you also pay attention to who's talking, what they're doing, and what happened in the previous panels. You might pay more attention to some parts than others. This is sort of like…

Explaining it for a slightly older audience, a transformer is a type of artificial neural network designed for processing sequences, like sentences in a text. It's especially known for its use in natural language processing (NLP), which is the field of AI that deals with understanding and generating human language. The Transformer is unique because it uses a mechanism called "attention" to understand the relationship…

Great explanation

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#114

Earlier quoted context omitted.

Yeah sorry, it still requires math and probably some exposure to ML basics.

I think one hole in the description for simplicity is that "differentiable" it's not an adjective that applies to hash tables. Differentiable relative to what? What is (x) in the d(hashtable)/d(x) equation?

That's exactly the point, though! It's surprising. A hashtable is a map from keys to values. Making it differentiable means that a small change in the key also makes a small change in the value!

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#115
Not sure I can give an ELI5 explanation, but for me this the closest to what you are after in two short videos on the topic. At least they helped me get up to speed fast.

Hope they will do the same for you ;-)

Large Language Models from scratch https://www.youtube.com/watch?v=lnA9DMvHtfI

Large Language Models: Part 2 https://www.youtube.com/watch?v=YDiSFS-yHwk

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#116
Well here is my (a bit cynical) take on it.

In the beginning, there was the matrix multiply. A simple neural network is a chain of matrix multiplies. Let's say you have your data A1 and weights W1 in a matrix. You produce A2 as A1xW1. Then you produce A3 as A2xW2, and so on. There are other operations in there like non-linearities (so that you can actually learn something interesting) and fancy batch norms, but let's forget about those for now. The problem with this is, it's not very expressive. Let's say your A1 matrix has just 2 values, and you want the output to be their product. Can you learn a weight matrix that performs multiplication of these inputs? No you can't. Multiplication must be simulated by piecing together piecewise linear functions. To perform multiplication, the weight matrix W would also need to be produced by the network. Transformers do basically that. In the product A*W you replace A with (AxW1), W with (AxW2), and multiply those together: (AxW1)x(AxW2) And then do it once more for good measure: (AxW1)x(AxW2)x(AxW3). Boom, Nobel prize. Now your network can multiply, not just add. OK it's actually a bit more complicated, there is for example a softmax in the middle to perform normalisation, which in general helps during numerical optimisation: softmax((AxW1)x(AxW2))x(AxW3). There are then fancy explanations that try to retrospectively justify this as a "differentiable lookup table" or somesuch nonsense, calling the 3 parts "key", "query" and "value", which help make your paper more popular. But the basic idea is not so complicated. A Transformer then uses this operation as a building block (running them in parallel an in sequence) to build giant networks that can do really cool things. Maybe you can teach networks to divide next and then you get the next Nobel prize.

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#117

This link was posted here recently, and was the most understandable explanation I've found so far: https://e2eml.school/transformers.html

Discussed here:

Transformers from Scratch (2021) - https://news.ycombinator.com/item?id=35697627 - April 2023 (46 comments)

Transformers from Scratch - https://news.ycombinator.com/item?id=29315107 - Nov 2021 (17 comments)

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#118

The Yannic kilcher review is quite good. https://youtu.be/iDulhoQ2pro I can't ELI5 but I can ELI-junior-dev. Tl;dw: Transformers work by basically being a differentiable lookup/hash table. First your input is tokenized and (N) tokens (this constitutes the attention frame) are encoded both based on token identity and position in the attention frame. Then there is an NxN matrix that is applied to your attention frame "…

what is a differentiable hash table? I understand differentiation, I don't understand differential hash table ... does that mean for every tiny gradient of a key, a corresponding gradient in value can be expected?

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#119
post #104
post #101

Has ELI5 lost its literal meaning? What five-year-old would understand anything in this thread?

It was never meant to be taken literally, it's just an idiomatic way of asking that something be explained as simply as possible. An answer to OP's question targeted at a five year old level would likely be impossible given the subject matter, or else need to be so general and simplistic as to be useless on this forum of not actual five year olds.

The current top comment managed it in a way that is actually useful: https://news.ycombinator.com/item?id=35981106

Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?

#120
Prompt: "ELI5 the Attention is All We Need paper."

Imagine you have a box of toys. Some toys are more interesting to you than others, so you pay more attention to those toys and play with them more. The same thing happens in the "Attention is All You Need" paper, but instead of toys, we have words in a sentence.

Before this paper, when computers tried to translate one language to another, they would look at one word, translate it, then move to the next word. This works okay, but it's not great because sometimes the meaning of a word can depend on other words in the sentence.

The clever thing about the "Attention is All You Need" paper is that it taught the computer to pay attention to all the words in a sentence at the same time, but give more importance ("attention") to the words that matter most for understanding and translation.

This new way of translating languages using "attention" made computers much better at understanding and translating languages. It's like if you could become better at playing by understanding all your toys at once! This paper was a big deal in the field of machine learning and artificial intelligence because it improved how machines understand languages.

Post reply on HN