LLMが「考える」仕組み
How LLMs "Think"
なぜLLMは「次の1語を予測するだけ」で複雑な論理思考ができるのか?——高次元空間の幾何学から見るAIの正体
大規模言語モデル(LLM)の基本原理は驚くほどシンプルだ。「入力された文章(トークン列)の続きとして、最も確率が高い『次の1語』を予測するニューラルネットワーク(NN)」に過ぎない。
それにもかかわらず、なぜLLMは数学の難問を解き、プログラミングのバグを見つけ、複雑な社会課題の解決策まで導き出せるのか?ブラックボックスとして語られがちなLLMの内部構造を、数理と幾何学の視点から徹底的に分解して整理する。
1. LLMの最小アルゴリズム(ブラックボックスなしの設計図)
LLMの内部では、魔法のような「論理エンジン」が動いているわけではない。行われているのは、以下の4ステップの純粋なベクトル演算だけである。
- 辞書の初期化(高次元・非直交空間の構築)
約20万語の単語(トークン)に対し、それぞれ4000次元などのベクトルを割り当てる。初期値は単なる乱数だ。4000次元もの広大な空間では、ランダムに配置されたベクトル同士は数学的性質(測度の集中)によりほぼ直交(非相関=内積がほぼ0)となり、混線のない「真っ白なキャンバス」が自動的に作られる。 - 並列レーンとアテンション(内積による動的な情報融合)
入力層から出力層まで「4000次元で一定」のパイプ(残差ストリーム)を、入力トークン数だけ並列に並べる。- トークン内部(横方向):各レーン内で重み行列による固定の変換を行う。
- トークン間(縦方向):固定の重み結合を持たず、毎層すべてのトークン同士で総当たりの「内積」を計算し、関連度の高い単語のベクトル成分を自分のベクトルに足し算(残差接続)して融合させる。
- 学習(BPによる空間の彫刻)
大量のテキストを使い、「次の1トークン」との内積が最大になるよう誤差逆伝播法(BP)で重みと辞書ベクトルを更新する。20万語を4000次元という「狭い部屋」に押し込んで圧縮するため、単なる丸暗記が不可能になり、言葉の裏にある共通の法則が空間の「形」として刻み込まれる。 - 推論(自己回帰ループとEOSによる停止)
重みを固定した状態で順方向(フォワード)計算を行い、最終層の最後のトークン位置から出た4000次元ベクトルと辞書全単語との内積をとる。最大の1語を出力し、それを末尾に加えた文章を再入力するループを繰り返す。そして、辞書に登録された停止信号(EOSトークン)が最大値として選ばれた瞬間に推論が終了する。
2. 核心:論理思考とは「多次元空間における幾何学的な近道」である
この単純な「内積と足し算の反復」からなぜ論理が生まれるのか。その答えは、論理を「意味の空間上における座標の平行移動(最短経路の探索)」として捉えることで一本の線に繋がる。
- 空間に刻まれた「法則のベクトル」
学習(BP)によって、4000次元空間の中には「前提Aから結論Cへ向かう矢印(論理の法則)」が幾何学的な構造として形成される。有名な「王様 - 男 + 女 = 女王」とまったく同じ幾何学的演算が、論理の世界でも起きている。 - 足し算の反復によるスライド
推論時、不変の4000次元空間の上で、各層のアテンションとNNが「文脈や論理ルールに応じた差分ベクトル」を計算し、元のベクトルに何十回も足し算(平行移動)していく。その結果、初期の「前提の座標」が論理の道に沿ってスライドし、最終層でピタリと「結論の座標」に着地する。
現実の複雑な問題解決も「ベクトルの足し算」で説明できる
例えば、「地方の深刻な人手不足(\(\vec{S}_{1}\))」と「都市部の高齢者の孤立(\(\vec{S}_{2}\))」という2つの社会問題をLLMに提示したとする。
4000次元空間では、両者は「労働力・役割のミスマッチ(符号が逆のベクトル)」という共通の幾何学的構造として抽出される。そこに他分野(電力融通やクラウドソーシングなど)から学習した「補完関係を作る解決ベクトル(\(\vec{V}_{\text{solve}}\))」が足し算されることで、「都市のシニア人材と地方企業をリモート・二拠点居住で結ぶマッチング基盤」という結論の座標へ一瞬でショートカット(着地)できる。
4000次元空間では、両者は「労働力・役割のミスマッチ(符号が逆のベクトル)」という共通の幾何学的構造として抽出される。そこに他分野(電力融通やクラウドソーシングなど)から学習した「補完関係を作る解決ベクトル(\(\vec{V}_{\text{solve}}\))」が足し算されることで、「都市のシニア人材と地方企業をリモート・二拠点居住で結ぶマッチング基盤」という結論の座標へ一瞬でショートカット(着地)できる。
3. 強化学習(RL)は「思考の黄金ルート」に繋がる
人間の文章を模倣するだけのBPには、「途中の思考プロセスをスをすっ飛ばして勘で答えを出し、計算ミス(座標のズレ)を起こしやすい」という弱点がある。
これを突破するのが、現代の推論モデルで採用されている強化学習(RL)だ。
構造や重み更新のエンジン(BP)は一切変えず、目的関数だけを切り替える。人間の採点コストを省くため、数学の数式一致やプログラムのテスト通過など「ハードコードで100%自動採点できる問題」を使い、AIに自由な思考プロセス(独り言)を書かせる。そして、最終回答が正解したルートだけをBPで強化する。
構造や重み更新のエンジン(BP)は一切変えず、目的関数だけを切り替える。人間の採点コストを省くため、数学の数式一致やプログラムのテスト通過など「ハードコードで100%自動採点できる問題」を使い、AIに自由な思考プロセス(独り言)を書かせる。そして、最終回答が正解したルートだけをBPで強化する。
これにより、AIは誰に教わるでもなく、空間上で脱線しないための「一度立ち止まって前提を疑う」「検算する」という汎用的な歩き方(思考アルゴリズム)を自力で獲得する。
4. 現在の限界と、次世代AIへの最後のピース
では、加減算(
+ と -)だけを教えたLLMに、時系列の周期分解(FFT)を報酬として長時間RLを回せば、自力で微積分やフーリエ変換を発明できるだろうか?小規模な周期性の再発見(グロッキング現象)は可能だが、ガウスの発散定理や伊藤のレンマのような高度な数学体系を築くには、現在のLLMには「辞書(トークン)が最初に固定されている」という致命的な限界がある。
人間の数学は、複雑な操作の塊に「微分(\(dy/dx\))」や「虚数(\(i\))」といった新しい記号(トークン)を割り当てて圧縮することで、思考の解像度を引き上げてきた。固定辞書のままでは、すべての式を元定義(加減算)から書き下す「金魚の糞」のような長文になり、入力窓や注意力の限界(アテンションの希釈)にぶつかってしまう。
現在、世界のAI研究の最前線では、「有効な思考パターンを新しい記号(ライブラリ)として動的に登録する技術」や、「文字に翻訳せず4000次元ベクトルのまま直接思考をループさせる技術(潜在推論)」の開発が急速に進んでいる。
まとめ
LLMの知性とは、人間のような意識や特別な論理回路の産物ではない。
「高次元の非直交空間に圧縮された言葉の地形の上で、内積によって文脈を結びつけ、差分の足し算(平行移動)を繰り返して結論の座標へと最短距離で滑り降りる幾何学的な計算プロセス」——これが、次の1語予測から論理思考が生まれるメカニズムの正体である。
「高次元の非直交空間に圧縮された言葉の地形の上で、内積によって文脈を結びつけ、差分の足し算(平行移動)を繰り返して結論の座標へと最短距離で滑り降りる幾何学的な計算プロセス」——これが、次の1語予測から論理思考が生まれるメカニズムの正体である。
How LLMs "Think"
Why Can LLMs Perform Complex Logical Reasoning Just by "Predicting the Next Word"? — The True Nature of AI Through the Geometry of High-Dimensional Space
The fundamental principle of a Large Language Model (LLM) is surprisingly simple. It is nothing more than a neural network (NN) that predicts the most probable "next word" to follow an input sequence of text (tokens).
Yet, how can an LLM solve difficult math problems, find programming bugs, and derive solutions to complex social issues? Let us thoroughly dissect and organize the internal structure of LLMs—often spoken of as a black box—from the perspectives of mathematics and geometry.
1. The Minimal Algorithm of an LLM (A Blueprint Without Black Boxes)
Inside an LLM, there is no magical "logic engine" at work. All that takes place are pure vector operations across the following four steps:
• Dictionary Initialization (Constructing a High-Dimensional, Non-Orthogonal Space)
Each of roughly 200,000 words (tokens) is assigned a vector of, say, 4,000 dimensions. The initial values are simply random numbers. In a vast space of 4,000 dimensions, randomly placed vectors become nearly orthogonal (uncorrelated, with a dot product close to 0) due to mathematical properties (concentration of measure), automatically creating a "blank canvas" free of interference.
• Parallel Lanes and Attention (Dynamic Information Fusion via Dot Products)
Pipes (residual streams) of a constant 4,000 dimensions—from the input layer to the output layer—are lined up in parallel, matching the number of input tokens.
• Within a token (horizontal direction): Fixed transformations are performed inside each lane using weight matrices.
• Between tokens (vertical direction): Without fixed weight connections, a brute-force "dot product" is calculated between all tokens at every layer, fusing the vector components of highly relevant words into one's own vector via addition (residual connections).
• Training (Sculpting the Space via Backpropagation)
Using massive amounts of text, weights and dictionary vectors are updated via backpropagation (BP) to maximize the dot product with the "next token." Because 200,000 words are compressed into a "cramped room" of 4,000 dimensions, rote memorization becomes impossible, and the underlying universal rules behind language are carved into the "shape" of the space.
• Inference (Autoregressive Loop and Halting via EOS)
With the weights fixed, a forward pass is computed, and the dot product is taken between the 4,000-dimensional vector emerging from the final token position of the last layer and every word in the dictionary. The single word with the highest score is output, appended to the end of the text, and fed back into the input in a repeating loop. Inference ends the instant the stop signal registered in the dictionary (the EOS token) is selected as the maximum value.
2. The Core: Logical Thinking Is a "Geometric Shortcut in Multi-Dimensional Space"
How does logic emerge from this simple repetition of dot products and addition? The answer connects into a single thread when we view logic as the "parallel translation of coordinates (finding the shortest path) within a semantic space."
• "Vectors of Laws" Carved into Space
Through training (BP), "arrows pointing from premise A to conclusion C (rules of logic)" are formed as geometric structures within the 4,000-dimensional space. The exact same geometric operation as the famous "King - Man + Woman = Queen" occurs in the realm of logic.
• Sliding Through Repeated Addition
During inference, within this invariant 4,000-dimensional space, the attention mechanisms and NNs at each layer calculate "differential vectors according to context and logical rules," adding them (parallel translation) to the original vector dozens of times. As a result, the initial "premise coordinates" slide along a logical path and land squarely on the "conclusion coordinates" at the final layer.
• Complex Real-World Problem Solving Can Also Be Explained by "Vector Addition"
Suppose we present an LLM with two social problems: "severe labor shortages in rural areas (\(\vec{S}_{1}\))" and "isolation of the elderly in urban areas (\(\vec{S}_{2}\))."
In the 4,000-dimensional space, both are extracted as a shared geometric structure: a "mismatch of labor and roles (vectors with opposite signs)." By adding a "solution vector that creates a complementary relationship (\(\vec{V}_{\text{solve}}\))" learned from other domains (such as power grid sharing or crowdsourcing), the model can take an instant shortcut (land) at the conclusion coordinates: "a matching platform connecting urban senior talent with rural businesses via remote work and dual-location living."
3. Reinforcement Learning (RL) Paves the "Golden Route of Thought"
BP, which merely imitates human text, has a weakness: it tends to skip intermediate thought processes, guess answers on intuition, and make calculation errors (coordinate drift).
Reinforcement Learning (RL), adopted in modern reasoning models, breaks through this limitation.
Without changing the architecture or the weight-update engine (BP) at all, only the objective function is switched. To avoid human grading costs, problems that can be 100% automatically graded via hard-coded rules—such as matching mathematical formulas or passing software unit tests—are used. The AI is allowed to write out free-form thought processes (monologues), and only the paths that reach the correct final answer are reinforced via BP.
Through this, without being taught by anyone, the AI independently acquires a general-purpose way of walking through the space (a thinking algorithm)—such as "pausing to question premises" and "double-checking calculations"—to avoid derailing.
4. Current Limitations and the Final Piece for Next-Generation AI
If we teach an LLM only addition and subtraction (\(+\) and \(-\)) and run RL for a long time using periodic decomposition of time-series data (FFT) as a reward, could it invent calculus or the Fourier transform on its own?
While rediscovering small-scale periodicity (the grokking phenomenon) is possible, building advanced mathematical systems like Gauss's divergence theorem or Itô's lemma faces a fatal limitation in current LLMs: the dictionary (tokens) is fixed from the beginning.
Human mathematics has raised the resolution of thought by compressing chunks of complex operations into new symbols (tokens), such as derivatives (\(dy/dx\)) or imaginary numbers (\(i\)). With a fixed dictionary, every equation must be written out from its basic definitions (addition and subtraction), resulting in endlessly trailing text that hits the limits of the context window and attention capacity (attention dilution).
Currently, at the forefront of global AI research, technologies are rapidly advancing to "dynamically register effective thought patterns as new symbols (libraries)" and to "loop thoughts directly as 4,000-dimensional vectors without translating them into text (latent reasoning)."
Summary
LLM intelligence is not the product of human-like consciousness or special logic circuits.
"A geometric computational process over a linguistic terrain compressed into a high-dimensional non-orthogonal space—connecting context via dot products and repeatedly adding differentials (parallel translation) to slide down the shortest path to the coordinates of a conclusion." — This is the true mechanism by which logical reasoning emerges from predicting the next word.


























































