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.
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
3 Token tiếp theo có xác suất cao nhất:
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.
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.
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.
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:
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.
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
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:
- Training: The model learns from millions of image-text pairs, understanding which words correspond to which visual concepts
- Diffusion Process: In many models, generation starts from random noise, and the model gradually refines the image, guided by your text prompt
- 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:
Prompt được tạo
a cat, photorealistic, golden hour, close-up portrait, peaceful
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:
- Temporal Understanding: Beyond single images, these models understand how things move and change over time
- Physics Simulation: They learn basic physics—how objects fall, how water flows, how people walk
- Frame Consistency: They maintain consistent subjects and scenes across many frames
- 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:
Prompt được tạo
A bird takes flight, slow pan left, 4 seconds
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 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:
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
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
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?
- It tries to write text that sounds good, not text that's always true
- The internet (where it learned) has mistakes too
- 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:
- The AI writes two different answers to the same question
- A human picks which answer is better
- The AI learns: "Okay, I should write more like Answer A"
- 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
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:
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 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.