Live data from Hacker News

I don't know how you get here from “predict the next word”

grumpy-economist.com

261–270 of 275 posts

Re: I don't know how you get here from “predict the next word”

#261
post #93

A while ago i did the nanogpt tutorial, i went through some math with pen and paper and noticed the loss function for 'predict the next token' and 'predict the next 2 tokens' (or n tokens) is identical. That was a bit of a shock to me so wanted to share this thought. Basically i think its not unreasonable to say llms are trained to predict the next book instead of single token. Hope this is usefull to someone.

I'd like to explore this idea, did you make a blog post about it? is it simple enough to post in the reply?

Unless I've misunderstood the math myself, I don't think GPs comment is quite right if taken literally since "predict the next 2 tokens" would literally mean predict index t+1, t+2 off of the same hidden state at index t, which is the much newer field of multi-token prediction and not classic LLM autoregressive training.

Instead what GP likely means is the observation that the joint probability of a token sequence can be broken down autogressively: P(a,b,c) = P(a) * P(b|a) * P(c|a,b) and then with cross-entropy loss which optimizes for log likelihood this becomes a summation. So training with teacher forcing to minimize "next token" loss simultaneously across every prefix of the ground-truth is equivalent to maximizing the joint probability of that entire ground-truth sequence.

Practically, even though inference is done one token at a time, you don't do training "one position ahead" at a time. You can optimize the loss function for the entire sequence of predictions at once. This is due the autoregressive nature of the attention computation: if you start with a chunk of text, as it passes through the layers you don't just end up with the prediction for the next word in the last token's final layer, but _all_ of the final-layer residuals for previous tokens will encode predictions for their following index.

So attention on a block of text doesn't give you just the "next token prediction" but the simultaneous predictions for each prefix which makes training quite nice. You can just dump in a bunch of text and it's like you trained for the "next token" objective on all its prefixes. (This is convenient for training, but wasted work for inference which is what leads to KV caching).

Many people also know by now that attention is "quadratic" in nature (hidden state of token i attends to states of tokens 1...i-1), but they don't fully grasp the implication that even though this means for forward inference you only predict the "next token", for backward training this means that error for token i can backpropagate to tokens 1...i-1. This is despite the causal masking, since token 1 doesn't attend to token i directly but the hidden state of token 1 is involved in the computation of the residual stream for token i.

When it comes to the statement

>its not unreasonable to say llms are trained to predict the next book instead of single token.

You have to be careful, since during training there is no actual sampling happening. We've optimized to maximize the joint probability of ground truth sequence, but this is not the same as maximizing the probability the the ground truth is generated during sampling. Consider that there could be many sampling strategies: greedy, beam search, etc. While the most likely next token is the "greedy" argmax of the logits, the most likely next N tokens is not always found by greedily sampling N times. It's thought that this is one reason why RL is so helpful, since rollouts do in fact involve sampling so you provide rewards at the "sampled sequence" level which mirrors how you do inference.

It would be right to say that they're trained to ensure the most likely next book is assigned the highest joint probability (not just the most likely next token is assigned highest probability).

Re: I don't know how you get here from “predict the next word”

#262
post #260

Earlier quoted context omitted.

No, it's not equivalent to nested if statements. If you can mathematically demonstrate that it is I would be interested. Anyway that's irrelevant. The point is that we use different language when referring to the one because its capabilities appear to be fundamentally different. Your argument comes down to a claim of human exceptionalism - that a computer program can never "understand" simply by virtue of being a com…

>No, it's not equivalent to nested if statements. It is. If you control the randomness involved, the output of a model is completely deterministic. Which means that it can be represented by a huge lookup table. Anything that can be represented by a lookup table can be expressed as an `if then else` statement.

By that logic sin(x) is equivalent to a lookup table. Yeah, you can approximate it that way. But doing so at any reasonable level of precision will quickly become an exercise in the absurd. Neural networks are far worse, consisting of stacks of massive linear combinations fed into nonlinear functions.

Regardless, it remains irrelevant to the subject at hand. You're going off on a tangent rather than admit your initial claim was wrong.

Re: I don't know how you get here from “predict the next word”

#263
post #260

Earlier quoted context omitted.

>No, it's not equivalent to nested if statements. It is. If you control the randomness involved, the output of a model is completely deterministic. Which means that it can be represented by a huge lookup table. Anything that can be represented by a lookup table can be expressed as an `if then else` statement.

By that logic sin(x) is equivalent to a lookup table. Yeah, you can approximate it that way. But doing so at any reasonable level of precision will quickly become an exercise in the absurd. Neural networks are far worse, consisting of stacks of massive linear combinations fed into nonlinear functions. Regardless, it remains irrelevant to the subject at hand. You're going off on a tangent rather than admit your initia…

>By that logic sin(x) is equivalent to a lookup table

NO!

`sin(x)` is continuous, so the domain is infinite.

But an LLM model is not a continuous function, and thus the domain of a LLM model is finite (set of all possible tokens). So using a lookup table for a model behavior would be exact and not an approximation. So it can indeed be represented by an if statement of finite size.

Hence proved!

If you don't understand something in what I wrote, I can clarify if you tell me where you have trouble following.

Re: I don't know how you get here from “predict the next word”

#264
post #93

A while ago i did the nanogpt tutorial, i went through some math with pen and paper and noticed the loss function for 'predict the next token' and 'predict the next 2 tokens' (or n tokens) is identical. That was a bit of a shock to me so wanted to share this thought. Basically i think its not unreasonable to say llms are trained to predict the next book instead of single token. Hope this is usefull to someone.

Are you referring to this one?: https://github.com/karpathy/build-nanogpt

Thats the one, lots of fun and a great entrypoint for experimentation.

Re: I don't know how you get here from “predict the next word”

#265
post #175
post #93

A while ago i did the nanogpt tutorial, i went through some math with pen and paper and noticed the loss function for 'predict the next token' and 'predict the next 2 tokens' (or n tokens) is identical. That was a bit of a shock to me so wanted to share this thought. Basically i think its not unreasonable to say llms are trained to predict the next book instead of single token. Hope this is usefull to someone.

Isn't that why noise was introduced (seed rolling/temperature/high p/low p/etc)? I mean it is still deterministic given the same parameters. But this might be misleadingly interpreted as an LLM having "thought out an answer" before generating tokens, which is an incorrect conclusion. Not suggesting you did.

Thats actually an interesting way to look at it. However i just posted that because i often see articles expressing amazement at how training an llm at next token prediction can take it so far. Seemingly ontrasting the simplicity of the training task to the complexity of the outcome. The insight is that the training task was in fact 'predict the next book', just as much as it is 'predict the next token'. So every time i see that 'predict the next token' representation of the training task it rubs me the wrong way. Its not wrong, but misleading.

I didnt mean to suggest that is how it 'thinks ahead' but i believe you can see it like that in a way. Because it has been trained to 'predict all the following tokens'. So it learned to guess the end of a phrase just as much as the beginning. I consider the mechanism of feeding each output token back in to be an implementation detail that distracts from what it actually learned to do.

I hope this makes sense. Fyi im no expert in any way, just dabbling.

Re: I don't know how you get here from “predict the next word”

#266
post #175

Earlier quoted context omitted.

Isn't that why noise was introduced (seed rolling/temperature/high p/low p/etc)? I mean it is still deterministic given the same parameters. But this might be misleadingly interpreted as an LLM having "thought out an answer" before generating tokens, which is an incorrect conclusion. Not suggesting you did.

> this might be misleadingly interpreted as an LLM having "thought out an answer" I'm convinced that that is exactly what happens. Anthropic confirms it: "Claude will plan what it will say many words ahead, and write to get to that destination. We show this in the realm of poetry, where it thinks of possible rhyming words in advance and writes the next line to get there. This is powerful evidence that even though mod…

This is about reasoning tokens right? I didnt mean that, nanogpt doesnt do that. Nanogpt inference just outputs letters directly, no intermediate tokens.

Re: I don't know how you get here from “predict the next word”

#267
post #249

Earlier quoted context omitted.

>You can reduce the human auditory process to a similar mechanical list. You can't. Because we don't know at which point sound gets registered in consciousness.

Because you can't even define what consciousness is, let alone objectively test for it. You are entirely wrong though. You most certainly _can_ reduce the human auditory process to a (bio)mechanical list. You have unilaterally, arbitrarily, and without justification added consciousness to that list.

>Because you can't even define what consciousness is, let alone objectively test for it.

Exactly. So if we understand "hearing" as something registered by consciousness, then implicitly things that are not conscious cannot "hear".

>reduce the human auditory process

Yes, human auditory process, yes. "Hearing" no. I see that you cleverly switched to the "auditory process" instead of "hearing". moving goal posts, are we?

Re: I don't know how you get here from “predict the next word”

#268
post #93

A while ago i did the nanogpt tutorial, i went through some math with pen and paper and noticed the loss function for 'predict the next token' and 'predict the next 2 tokens' (or n tokens) is identical. That was a bit of a shock to me so wanted to share this thought. Basically i think its not unreasonable to say llms are trained to predict the next book instead of single token. Hope this is usefull to someone.

I'd like to explore this idea, did you make a blog post about it? is it simple enough to post in the reply?

No blog post, my llm expert friend told me this was kinda obvious when i shared it with him so i didnt think it was worth it.

I can tell you how i got there, i did nanogpt, then tried to be smart and train a model with a loss function that targets 2 next tokens instead of one. Calculate the loss function and you'll see its exactly the same during training.

Sibling commenter also mentions:

> the joint probability of a token sequence can be broken down autogressively: P(a,b,c) = P(a) * P(b|a) * P(c|a,b) and then with cross-entropy loss which optimizes for log likelihood this becomes a summation."

Hope that helps.

Re: I don't know how you get here from “predict the next word”

#269

Earlier quoted context omitted.

I'd like to explore this idea, did you make a blog post about it? is it simple enough to post in the reply?

Unless I've misunderstood the math myself, I don't think GPs comment is quite right if taken literally since "predict the next 2 tokens" would literally mean predict index t+1, t+2 off of the same hidden state at index t, which is the much newer field of multi-token prediction and not classic LLM autoregressive training. Instead what GP likely means is the observation that the joint probability of a token sequence ca…

The idea i tried to express was purely the loss function thing you mentioned, and how both tasks (1 vs 2 vs n) lead to identical training runs. At least with nanogpt. I dont know if that extrapolates well to current llm internals and current training.

Re: I don't know how you get here from “predict the next word”

#270
post #260

Earlier quoted context omitted.

No, it's not equivalent to nested if statements. If you can mathematically demonstrate that it is I would be interested. Anyway that's irrelevant. The point is that we use different language when referring to the one because its capabilities appear to be fundamentally different. Your argument comes down to a claim of human exceptionalism - that a computer program can never "understand" simply by virtue of being a com…

>No, it's not equivalent to nested if statements. It is. If you control the randomness involved, the output of a model is completely deterministic. Which means that it can be represented by a huge lookup table. Anything that can be represented by a lookup table can be expressed as an `if then else` statement.

That’s not true in practice thought https://sulbhajain.medium.com/why-llms-arent-truly-determini...
Post reply on HN