Chapter 3

Technical principles: in-depth analysis of LLM core mechanisms

Only by understanding how AI “thinks” can you collaborate with it better.

Token: the world through AI’s eyes

A Token is the basic unit AI uses to process text. One Token is roughly 4 English characters or 1–2 Chinese characters.

Example:

“Hello World” = [“Hello”, “ World”] = 2 tokens

“Hello world” = [“Hello”, “world”] = 2 tokens

Context Window (Context Window)

The Context Window is the amount of text an AI can “see” at one time. You can think of it as the AI's “working memory”.

GPT-3.5
4K
A short article
GPT-4
128K
A novel
Claude 3
200K
Several books

Attention: how does AI “focus” on key points?

Highlighter theory

Imagine reading an article and using a highlighter to mark the key points. The Attention mechanism is AI’s “highlighter”; it automatically finds the most relevant parts of the text.

For example, when AI processes this sentence:

“The cat sat on the mat because it was tired.”

AI will notice that “it” refers to “cat”

Practical significance

Good naming makes it easier for AI to understand your code.userProfile than data1 It is more meaningful, and AI will better understand the context.

Prompt engineering

RTCC framework

RRole

You are a senior front-end engineer...

TTask (task)

Help me create a login form...

CContext (context)

Using React and Tailwind...

CConstraint (constraint)

Do not use third-party UI libraries...

Chain of Thought(CoT)

Let AI "slow down and think," reasoning step by step instead of giving an answer directly.

General question:

“Which is larger, 9.11 or 9.8?”

CoT question:

“Which is larger, 9.11 or 9.8? Think step by step.”

Few-Shot Learning

By giving the AI a few examples, teach it to learn the style and format you want.

Input: apple
Output: apple

Input: banana  
Output: banana

Input: orange
Output: 

Prompt vs Context

Many people focus too much on prompt techniques and overlook the importance of context. Providing AI with sufficient context (code, documentation, and examples) is more effective than carefully crafting a prompt.