·9 min read

What Algorithms Does AI Use for Thinking, and How to Them?

By Aleksei Zulin

Most people are using AI wrong - and the reason is embarrassingly simple. They treat it like a search engine with better grammar. The real comes from understanding what's actually happening inside, at least roughly, and then designing your prompts to work with the architecture instead of against it.

Here's the direct answer: modern large language models think through a combination of transformer-based attention mechanisms, next-token prediction, and increasingly, chain-of-thought reasoning scaffolds. Attention tells the model what parts of a prompt to weight heavily. Next-token prediction generates output by repeatedly asking "what word is most probable given everything before it?" Chain-of-thought extends this into something that looks like stepwise reasoning - the model talks itself through a problem before committing to an answer.

None of these are "thinking" in the human sense. But that distinction matters less than you'd expect. What matters is that each mechanism creates a specific point. Attention responds to structure and salience. Prediction responds to priming. Chain-of-thought responds to explicit reasoning invitations. If you know which lever you're pulling, you can pull it deliberately.

That's the whole game.


Attention Is the Foundation - and Most People Ignore It

The transformer architecture, introduced by Vaswani et al. in the landmark 2017 paper "Attention Is All You Need" (Google Brain), fundamentally changed what AI could do with language. Before transformers, models processed text sequentially - word by word, losing context as distance grew. Attention mechanisms allow the model to look across the entire input simultaneously, assigning weights to relationships between tokens regardless of how far apart they appear.

What this means practically: the model doesn't read your prompt the way you do. It doesn't start at the top and build a mental model. It constructs a weighted graph of relationships across everything at once. Early tokens and late tokens often receive disproportionate attention weight - a pattern Anthropic's interpretability researchers have noted in red-teaming and circuit analysis work. The middle of long prompts? Frequently underweighted.

This has a name in the literature. The "lost in the middle" phenomenon, documented by Nelson Liu and colleagues at Stanford's NLP Group in their 2023 paper of the same name, showed that retrieval accuracy drops significantly when relevant information is buried in the center of long contexts. Models performed best when key facts appeared at the very beginning or very end of the prompt. The effect held across multiple frontier models and was robust enough that the authors recommended it as a practical design principle.

The point follows directly. Put your most important constraint, context, or instruction at the top of the prompt. Repeat critical information near the end. Don't assume the model read the middle carefully - it probably didn't, at least not with full weight.


Next-Token Prediction and the Priming Effect

Every output an LLM generates is, at its mechanical core, a probability distribution over the next possible token. The model samples from that distribution, appends the token, then does it again. Thousands of times per response. This sounds reductive, but the emergent behavior from billions of parameters doing this at scale is genuinely surprising - and exploitable.

Priming is the key concept here. Geoffrey Hinton, speaking at a 2023 MIT lecture after his departure from Google, described how LLMs internalize enormous statistical regularities about how certain kinds of text continue. When you begin a prompt in a particular register - academic, casual, technical, narrative - you're loading a probability distribution that tends to sustain that register throughout the response.

If you start a prompt with "Explain briefly," you get brevity. If you start with "Walk me through your reasoning step by step," something different happens - the model generates reasoning steps because that's what text structured that way typically contains. You're not asking the model to think differently. You're loading a different prior.

The mistake most people make is front-loading context about themselves - "I'm a marketer working on a campaign for a B2B SaaS company in the fintech space..." - when they should be front-loading the form of the response they want. Format is a priming signal. The model will try to continue whatever genre you've initiated.


Chain-of-Thought: The Closest Thing to Deliberate Reasoning

In 2022, Google Brain researchers Jason Wei, Xuezhi Wang, and colleagues published "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models," demonstrating that asking models to show their work - literally including phrases like "let's think step by step" - dramatically improved performance on multi-step math and logic tasks. The improvement wasn't marginal. On some benchmarks, accuracy nearly doubled compared to standard prompting on the same models.

Why does this work? The mechanistic explanation is still debated, which is worth sitting with for a moment. One interpretation: generating intermediate reasoning steps forces the model to use more of its representational capacity before committing to a final answer, rather than mapping directly from question to conclusion through shallow pattern matching. Another interpretation: it primes the output toward text that looks like careful reasoning, and text that looks like careful reasoning tends to contain fewer errors because that's what the training data contained.

Probably both. The exact mechanism matters less than the practical upshot.

Chain-of-thought prompting works best on tasks with verifiable intermediate steps - math, code, logical deduction. It works poorly on tasks that require genuine world knowledge the model doesn't have, or on highly creative tasks where you actually want fast associative leaps rather than grinding through steps. Forcing a haiku into chain-of-thought reasoning is, in my experience, a reliable way to get mediocre haiku.


Reinforcement Learning from Human Feedback: How AI Learned to Sound Useful

The algorithms above describe how LLMs generate text. But the reason they sound helpful - rather than like autocomplete on a corrupted hard drive - is a training method called Reinforcement Learning from Human Feedback, or RLHF. The technique was introduced in its modern form by Paul Christiano and colleagues at OpenAI in their 2017 paper "Deep Reinforcement Learning from Human Preferences," and later operationalized at scale by Long Ouyang et al. in the 2022 InstructGPT paper, which became the direct precursor to ChatGPT.

The process works like this: human raters compare model outputs and indicate which response is better. A reward model learns to predict these preferences. The language model is then optimized - via reinforcement learning - to generate outputs the reward model scores highly.

This creates a peculiar dynamic. The model has been optimized to generate text humans rate as good, which is correlated with but not identical to text that is good. Confident-sounding answers get rated highly. Hedged, uncertain answers get rated lower, even when the uncertainty is epistemically appropriate. RLHF essentially trained models to project confidence.

this asymmetrically. When you need the model to admit uncertainty, explicitly ask it to tell you what it doesn't know, or what assumptions it's making. Otherwise, it will often produce confident-sounding text that papers over genuine uncertainty - because that's what the training signal rewarded.


Limitations

These mechanisms explain a lot, but they don't explain everything, and precision about the limits matters here.

Interpretability research is still early. We don't have a complete, mechanistic account of how transformer representations map to specific behaviors. Nelson Elhage and colleagues at Anthropic published "A Mathematical Framework for Transformer Circuits" in 2021, making real progress on small toy models - but scaling these findings to frontier systems remains an open research problem. The gap between what we understand in simplified circuits and what drives behavior in a 70-billion-parameter model is not closed.

The points described here - attention weighting, priming, chain-of-thought, RLHF dynamics - are real, but the effects are probabilistic and context-dependent. They increase your odds of better outputs; they don't guarantee them. In domains with sparse training data representation, these techniques may yield smaller gains. And none of this resolves hallucination - the model confidently generating false information - which remains an active research problem without a clean solution. Use these techniques as probability-shifters, not certainty-providers.


FAQ

Does understanding these algorithms make you a better AI user if you're not technical?

Yes, because the points are behavioral, not technical. You don't need to implement attention mechanisms - you need to understand that the model weights early information heavily. That insight takes 30 seconds to apply and changes how you structure prompts immediately.

Is chain-of-thought prompting always better?

No. For simple factual queries or tasks requiring fast associative leaps - like creative brainstorming - forcing stepwise reasoning can actually constrain output quality. Use it specifically when intermediate verification steps matter, or when the task has logical dependencies that need to be resolved sequentially.

Why does the same prompt give different results each time?

Temperature settings and sampling randomness. The model doesn't select the single most probable token - it samples from a distribution. Higher temperature settings increase variance in outputs. If consistency matters, lower temperature settings or explicit formatting constraints reduce that variance significantly.

Can you "jailbreak" your own prompts - get better outputs by understanding RLHF?

In a legitimate sense, yes. RLHF trained models toward confident, agreeable outputs. Explicitly prompting for uncertainty ("what are you least confident about in this response?"), devil's advocate reasoning, or steelmanned counterarguments counteracts the sycophancy gradient and produces more epistemically honest outputs.


From here, the natural next questions are about cognitive partnership - how to structure an ongoing workflow with AI that leverages these mechanisms across multiple sessions, not just single prompts. That connects directly to context window management and how memory (or the absence of it) shapes what AI can actually do across a project. The question of whether AI reasoning scales - whether larger models think qualitatively differently or just more fluently - is equally worth your time.

Related Articles

About the Author

Aleksei Zulin is the author of The Last Skill, a book on how to think with AI as a cognitive partner rather than use it as a tool. Systems engineer turned writer exploring the frontier of human-AI collaboration.

The Last Skill is a book about thinking with AI as a cognitive partner.

Get The Book - $29