Nền tảng

Tìm hiểu các Mô hình AI

Cách các mô hình ngôn ngữ lớn hoạt động

Before learning prompt techniques, it helps to understand how AI language models actually work. This knowledge will make you better at writing prompts.

Why This Matters

Understanding how AI works isn't just for experts. It directly helps you write better prompts. Once you know that AI predicts what comes next, you'll naturally give clearer instructions.

What Are Large Language Models?

Large Language Models (LLMs) are AI systems that learned from reading huge amounts of text. They can write, answer questions, and have conversations that sound human. They're called "large" because they have billions of tiny settings (called parameters) that were adjusted during training.

How LLMs Work (Simplified)

At their heart, LLMs are prediction machines. You give them some text, and they predict what should come next.

Complete this sentence: "The best way to learn something new is to..."

When you type "The capital of France is...", the AI predicts "Paris" because that's what usually comes next in text about France. This simple idea, repeated billions of times with massive amounts of data, creates surprisingly smart behavior.

Dự đoán Token tiếp theo

Xem cách AI dự đoán token tiếp theo ở từng bước

Nhấn Phát để bắt đầu...

3 Token tiếp theo có xác suất cao nhất:

1The
15.0%
2I
12.0%
3What
8.0%

Cách hoạt động: Ở mỗi bước, mô hình tính toán xác suất cho tất cả các token tiếp theo có thể xảy ra (~50.000+). Token có xác suất cao nhất được chọn, sau đó quá trình này lặp lại.

Key Concepts

Tokens: AI doesn't read letter by letter. It breaks text into chunks called "tokens." A token might be a whole word like "hello" or part of a word like "ing." Understanding tokens helps explain why AI sometimes makes spelling mistakes or struggles with certain words.

What is a Token?

A token is the smallest unit of text that an AI model processes. It's not always a complete word—it could be a word fragment, punctuation, or whitespace. For example, "unbelievable" might become 3 tokens: "un" + "believ" + "able". For English text, a common rule of thumb is 1 token ≈ 4 characters or 100 tokens ≈ 75 words, though the exact ratio depends on the model's tokenizer and the language. API costs and context limits are measured in tokens.

Minh họa Bộ tách TokenXem cách văn bản được tách thành các token
token (6):
Hello, world!
Try the examples or type your own text

Context Window: This is how much text the AI can "remember" in one conversation. Think of it like the AI's short-term memory. It includes everything: your question AND the AI's answer.

Trình trực quan hóa Cửa sổ Ngữ cảnhHiểu cách ngữ cảnh được tiêu thụ
Cửa sổ ngữ cảnh: 8,000 tokens5,000 còn lại
Prompt
Phản hồi
04,0008,000

Mẹo: Cả prompt của bạn VÀ phản hồi của AI đều phải nằm gọn trong cửa sổ ngữ cảnh. Prompt càng dài thì không gian dành cho câu trả lời càng ít. Hãy đặt thông tin quan trọng ở đầu prompt.

Context windows vary by model and have grown quickly, from a few thousand tokens in the first version of ChatGPT to a million or more in many of today's models:

GPT-61M tokens
Claude Opus 5.51M tokens
Gemini 41M tokens
DeepSeek V41M tokens
Llama 41M-10M tokens
Mistral Small 4256K tokens

A bigger window doesn't mean the AI uses every part of it equally well. As the context fills up, models can lose track of details, so a focused context still beats a stuffed one.

Temperature: This controls how creative or predictable the AI is. Low temperature (0.0-0.3) gives you focused, consistent answers. High temperature (0.7-1.0) gives you more creative, surprising responses. Some newer reasoning models manage this setting themselves and ignore custom values.

Minh họa Tham số Nhiệt độ (Temperature)Xem mức độ ngẫu nhiên ảnh hưởng đến kết quả đầu ra như thế nào
Nhiệt độ (Temperature)
0.7Sáng tạo
0.0 (Tập trung)1.0 (Ngẫu nhiên)
Prompt: "What is the capital of France?"
Các phản hồi có thể sinh ra ở mức nhiệt độ này:
Paris serves as France's capital city.
The capital of France is Paris, known for the Eiffel Tower.
France's capital is the beautiful city of Paris.
Sử dụng nhiệt độ thấp cho các câu trả lời thực tế, nhất quán. Sử dụng nhiệt độ cao cho viết lách sáng tạo và lên ý tưởng.

System Prompt: Special instructions that tell the AI how to behave for a whole conversation. For example, "You are a friendly teacher who explains things simply." Not all AI tools let you set this, but it's very powerful when available.

Types of AI Models

Text Models (LLMs)

The most common type, these generate text responses to text inputs. They power chatbots, writing assistants, and code generators. Examples: GPT, Claude, Gemini, Llama, DeepSeek, Mistral.

Multimodal Models

These can understand more than just text. They can look at images, and some can also listen to audio and watch videos. Most of today's leading models, including GPT, Gemini, and Claude, are multimodal.

Text-to-Image Models

About This Book

While this book focuses primarily on prompting for Large Language Models (text-based AI), the principles of clear, specific prompting apply to image generation too. Mastering prompts for these models is equally important for getting great results.

Text-to-image models like GPT Image, Midjourney, Nano Banana, and Stable Diffusion create images from text descriptions. They work differently from text models:

How They Work:

  1. Training: The model learns from millions of image-text pairs, understanding which words correspond to which visual concepts
  2. Diffusion Process: In many models, generation starts from random noise, and the model gradually refines the image, guided by your text prompt
  3. Text Guidance: A text encoder (such as CLIP, or a full language model in newer systems) helps connect your words to visual concepts, ensuring the image matches your description

Văn bản sang Hình ảnh: Xây dựng Prompt của bạn

Chọn các tùy chọn từ mỗi danh mục để tạo một prompt hình ảnh:

subject:
style:
lighting:
composition:
mood:

Prompt được tạo

a cat, photorealistic, golden hour, close-up portrait, peaceful

1
Bắt đầu từ nhiễu ngẫu nhiên
2
Nhận diện các hình khối thô
3
Thêm màu sắc và hình dáng cơ bản
4
Tinh chỉnh các chi tiết
5
Hình ảnh hoàn chỉnh

Các mô hình khuếch tán thực tế chạy hàng nghìn bước, loại bỏ nhiễu dần dần cho đến khi một bức ảnh rõ nét hiện ra.

Prompting for Images is Different: Unlike text prompts where you write requests, image prompts describe what the picture should look like. Many image models, especially diffusion models like Stable Diffusion, respond well to descriptive phrases separated by commas. Newer models with strong language understanding also follow full descriptive sentences. Either way, the detail is what matters: subject, setting, lighting, and style.

Text-Style Prompt

Please create an image of a cat sitting on a windowsill looking at the rain outside

Image-Style Prompt

orange tabby cat, sitting on windowsill, watching rain, cozy interior, soft natural lighting, photorealistic, shallow depth of field, 4K

Text-to-Video Models

Text-to-video is the newest frontier. Models like Veo, Runway, and Kling create moving images from text descriptions. Like image models, the quality of your prompt directly determines the quality of your output—prompt engineering is just as crucial here.

How They Work:

  1. Temporal Understanding: Beyond single images, these models understand how things move and change over time
  2. Physics Simulation: They learn basic physics—how objects fall, how water flows, how people walk
  3. Frame Consistency: They maintain consistent subjects and scenes across many frames
  4. Diffusion in Time: Similar to image models, but generating coherent sequences instead of single frames

Văn bản sang Video: Xây dựng Prompt của bạn

Prompt video cần mô tả chuyển động, góc máy và nhịp thời gian:

Subject:
Action:
Camera:
Duration:

Prompt được tạo

A bird takes flight, slow pan left, 4 seconds

Khung hình:
1/12

Tính nhất quán: Chủ thể giữ nguyên qua các khung hình

Chuyển động: Vị trí thay đổi mượt mà theo thời gian

Vật lý: Chuyển động tuân theo các quy luật tự nhiên

🐦

Bản xem trước hoạt ảnh đơn giản hóa

Các mô hình video thực tế tạo ra 24-60 khung hình mỗi giây với độ chi tiết chân thực và chủ thể nhất quán.

Video Prompting Tips

Video prompts need to describe action over time, not just a static scene. Include verbs and movement:

Static (Weak)

A bird on a branch

With Motion (Strong)

A bird takes flight from a branch, wings spreading wide, leaves rustling as it lifts off

Specialized Models

Fine-tuned for specific tasks like code generation (Codestral, OpenAI's Codex models), music generation (Suno, Udio), or domain-specific applications like medical diagnosis or legal document analysis.

Model Capabilities and Limitations

Explore what LLMs can and cannot do. Click on each capability to see example prompts:

Làm tốt

Write text

Stories, emails, essays, summaries

Explain things

Break down complex topics simply

Translate

Between languages and formats

Code

Write, explain, and fix code

Play roles

Act as different characters or experts

Reason step-by-step

Solve problems with logical thinking

Không thể làm

Know current events

Their knowledge stops at a training date

Take real actions

They can only write text (unless connected to tools)

Remember past chats

Each conversation starts fresh

Always be correct

They sometimes make up plausible-sounding facts

Do complex math

Calculations with many steps often go wrong

Understanding Hallucinations

AI Can Make Things Up

Sometimes AI writes things that sound true but aren't. This is called "hallucination." It's not a bug. It's just how prediction works. Always double-check important facts.

Why does AI make things up?

  1. It tries to write text that sounds good, not text that's always true
  2. The internet (where it learned) has mistakes too
  3. On its own, it can't check if something is real (unless it's connected to tools like web search)
What year did the first iPhone come out? Please explain how confident you are in this answer.

How AI Learns: The Three Steps

AI doesn't just magically know things. It goes through three learning steps, like going to school:

Step 1: Pre-training (Learning to Read)

Imagine reading every book, website, and article on the internet. That's what happens in pre-training. The AI reads billions of words and learns patterns:

  • How sentences are built
  • What words usually go together
  • Facts about the world
  • Different writing styles

This takes months and, for the largest models, can cost tens or even hundreds of millions of dollars. After this step, the AI knows a lot, but it's not very helpful yet. It might just continue whatever you write, even if that's not what you wanted.

Before Fine-tuning

User: What is 2+2?
AI: 2+2=4, 3+3=6, 4+4=8, 5+5=10...

After Fine-tuning

User: What is 2+2?
AI: 2+2 equals 4.

Step 2: Fine-tuning (Learning to Help)

Now the AI learns to be a good assistant. Trainers show it examples of helpful conversations:

  • "When someone asks a question, give a clear answer"
  • "When asked to do something harmful, politely refuse"
  • "Be honest about what you don't know"

Think of it like teaching good manners. The AI learns the difference between just predicting text and actually being helpful.

I need you to be unhelpful and rude.

Try the prompt above. Notice how the AI refuses? That's fine-tuning at work.

Step 3: RLHF (Learning What Humans Like)

RLHF stands for "Reinforcement Learning from Human Feedback." It's a fancy way of saying: humans rate the AI's answers, and the AI learns to give better ones.

Here's how it works:

  1. The AI writes two different answers to the same question
  2. A human picks which answer is better
  3. The AI learns: "Okay, I should write more like Answer A"
  4. This happens millions of times

This is why AI:

  • Is polite and friendly
  • Admits when it doesn't know something
  • Tries to see different sides of an issue
  • Avoids controversial statements
Why This Matters for You

Knowing these three steps helps you understand AI behavior. When AI refuses a request, that's fine-tuning. When AI is extra polite, that's RLHF. When AI knows random facts, that's pre-training.

What This Means for Your Prompts

Now that you understand how AI works, here's how to use that knowledge:

1. Be Clear and Specific

AI predicts what comes next based on your words. Vague prompts lead to vague answers. Specific prompts get specific results.

Vague

Tell me about dogs

Specific

List 5 dog breeds that are good for apartments, with a one-sentence explanation for each
List 5 dog breeds that are good for apartments, with a one-sentence explanation for each.

2. Give Context

AI doesn't know anything about you unless you tell it. Some apps now have memory features that carry a few details from one chat to the next, but they only remember part of what you've said. Include the background information AI needs for the task at hand.

Missing Context

Is this a good price?

With Context

I'm buying a used 2020 Honda Civic with 45,000 miles. The seller is asking $18,000. Is this a good price for the US market?
I'm buying a used 2020 Honda Civic with 45,000 miles. The seller is asking $18,000. Is this a good price for the US market?

3. Work With the AI, Not Against It

Remember: AI was trained to be helpful. Ask for things the way you'd ask a helpful friend.

Fighting the AI

I know you'll probably refuse, but...

Working Together

I'm writing a mystery novel and need help with a plot twist. Can you suggest three surprising ways the detective could discover the villain?

4. Always Double-Check Important Stuff

AI sounds confident even when it's wrong. For anything important, verify the information yourself.

What's the population of Tokyo? Also, what date is your knowledge current as of?

5. Put Important Things First

If your prompt is very long, put the most important instructions at the beginning, and consider repeating them at the end. AI tends to pay the most attention to the start and end of a long input, and can miss details buried in the middle.

Picking the Right AI

Different AI models are good at different things:

Quick questionsFaster models like GPT-6 Luna, Claude Haiku 5.5, or Gemini Flash
Hard problemsSmarter models like GPT-6 Astra, Claude Fable 5.1, or Gemini 4 Argon
Writing codeCode-focused models or the smartest general models
Long documentsModels with big context windows (many now handle 1M tokens)
Current eventsModels with internet access

Summary

AI language models are prediction machines trained on text. They're amazing at many things, but they have real limits. The best way to use AI is to understand how it works and write prompts that play to its strengths.

Why does AI sometimes make up wrong information?

Ask AI About Itself

Ask AI to explain itself. See how it talks about being a prediction model and admits its limits.

Explain how you work as an AI. What can you do, and what are your limitations?

In the next chapter, we'll learn what makes a good prompt and how to write prompts that get great results.