LLM이 실제로 하는 일: 다음 단어 예측 설명

발행: (2026년 6월 18일 AM 12:42 GMT+9)
3 분 소요
원문: Dev.to

출처: Dev.to

데브샨후 비스와스 (https://dev.to/dev48v)

How does ChatGPT think? It don’ t. The entire mechanism behind every chatbot is almost anticlimactic: it predicts one next word, adds it, and repeats. I built a tiny interactive predictor so you can be the model — and it explains both the magic and the flaws. 🔮 Be the model: https://dev48v.infy.uk/ai/days/day6-next-token.html This is Day 6 of AIFromZero — AI literacy, one concept a day, no code to follow.

  1. It only predicts the NEXT word
    Given everything so far, the model outputs a probability for every possible next word, picks one, appends it, and runs again with the longer text. Paragraphs, code, poems — all of it is this one step on repeat.
    ”the cat sat on the ___ ” → P(mat) high, P(bird) low

  2. It’ s a probability over the WHOLE vocabulary
    The output isn’t one word — it’s a number for every word it knows (100,000+ for a real model). Most are near zero; a handful are plausible. The bars in the demo are that distribution, over a tiny vocabulary.

  3. Autoregression: feed the output back in
    After picking a word, it becomes part of the input for the next prediction. Predict → append → predict again. Because each new word conditions on all the previous ones, short local choices add up to coherent long text.

  4. Temperature = the creativity dial
    Once you have probabilities, how do you choose? Temperature reshapes them before sampling:

  • Near 0: the top word always wins — safe, repetitive. High: the odds flatten, so rarer words get a real chance — creative, error-prone.
p = p  ** (1 / temperature);    // then renormalise and sample

Enter fullscreen mode

Exit fullscreen mode

Drag the slider in the demo and watch the bars sharpen or even out. That one knob is what an API calls “creativity.”

  1. Where do the probabilities come from?
    In my toy, from counting which word followed which in a few sentences (a “bigram” with 1-word memory). A real LLM replaces the counting with a giant neural network trained on much of the internet, and its memory spans thousands of words. The mechanism is identical — only the quality of the guess changes.

  2. Why this explains so much

“Just predicting the next word” explains the fluency (it has seen how language flows) AND the hallucinations: a plausible-sounding next word isn’t always a true one. It optimises for likely, not correct. That gap is where made-up facts live — and it’s tomorrow’ s topic.

The takeaway

Predict next word → append → repeat; temperature tunes the daring. Understand this loop and “the AI thinks…” stops being mysterious and starts being mechanical. Try being the model — click words and watch a sentence build.

0 조회
Back to Blog

관련 글

더 보기 »