Understand how LLMs work: from training on massive text corpora to real-time inference. Learn when to use prompts, RAG, or fine-tuning for your AI projects.
LLM Literacy 101: How Large Language Models Learn & Infer
核心 Summary
- LLMs train on enormous text corpora (15+ trillion bytes) converted into tokens — the fundamental units that models learn from
- Training involves two core processes: learning (adjusting parameters through backpropagation) and inference (predicting the next token based on learned patterns)
- Parameters are weight settings in neural networks (billions of them), adjusted during training like a DJ tuning different controls for optimal output
- Inference uses the Transformer architecture with attention mechanisms to determine relationships between tokens and select the best next token
- Three strategies exist for solving problems: use prompts for general tasks, RAG for evidence-based answers with up-to-date information, and fine-tuning only for large-scale repetitive domain-specific tasks
How LLMs Learn: The Training Process
Large Language Models don't start intelligent—they're built through a methodical training process. The journey begins with a corpus: vast amounts of publicly available text from the internet, comprising trillions of bytes. This raw text must be transformed into a format machines can process.
The first critical step is tokenization. A token isn't simply a word; it's a compressed unit created by identifying and grouping repeating character patterns. Using an algorithm similar to image compression (like JPG), the model's vocabulary extracts common combinations and assigns each a unique ID. This is why the same phrase might tokenize differently across models—each model has its own vocabulary built during training.
Once tokenized, the training process begins. The model is presented with token sequences and asked to predict the next token. Initially, predictions are random, distributed across all possible vocabulary items. Through backpropagation, the model identifies its errors and adjusts millions or billions of parameters—essentially weight settings that control how the neural network processes information. Think of parameters like a DJ adjusting control knobs; tiny changes in these settings produce vastly different outputs. This cycle repeats billions of times until the model accurately predicts appropriate next tokens.
This foundational training phase is called pre-training, and it consumes extraordinary computational resources—enough electricity to power thousands of households for days.
Understanding Inference: How LLMs Generate Responses
After training, models must perform inference—the actual process of generating your responses when you type a prompt. Inference is fundamentally different from training: parameters remain frozen; the model uses learned knowledge to predict tokens sequentially.
When you submit a prompt, it's first converted into tokens, then embedded (transformed into numerical representations). This input flows through multiple layers of processing, each layer performing identical operations repeatedly to progressively narrow down the best candidate tokens.
The core mechanism is attention: the model calculates relationships between tokens to determine which preceding tokens are most relevant to the current prediction. For example, in "My cat's name is Roy. Its breed is Bengal. Roy is a cat," the model recognizes that "Roy" and "cat" are closely related, while "lives in our house" has weaker relevance. These attention calculations repeat across many layers and multiple attention heads, creating increasingly refined candidate pools.
At each layer's end, softmax converts raw scores into normalized probabilities (summing to 1.0). Then sampling occurs—using parameters like temperature, top-k, and top-p to determine which final token is selected. Higher temperature settings increase randomness (more creative outputs), while lower temperatures favor the highest-probability tokens (more deterministic results). This isn't a single calculation; it's a probabilistic coin flip among weighted candidates.
Crucially, this entire process is then cached—once tokens are generated, they're stored so subsequent predictions don't recalculate everything. The model stops only when it produces a special "stop token," which it learned during post-training.
When to Use Prompts, RAG, or Fine-Tuning
Understanding training and inference reveals when each strategy works best.
Prompts should be your default. For most tasks—formatting output, answering questions, coding assistance—careful prompt engineering works with modern models like Claude or GPT-4. Even complex instructions embedded in system prompts often succeed without additional overhead.
RAG (Retrieval-Augmented Generation) becomes necessary when you need evidence-based answers or must incorporate frequently updated information. Instead of putting massive rulebooks into your prompt (which would bloat the token sequence and overwhelm attention mechanisms), RAG retrieves only relevant context and inserts it into the inference process. This is ideal for legal documents, knowledge bases, or any scenario requiring grounded, up-to-date responses.
Fine-tuning should be rare. It's cost-effective only at scale—when you're running the same task millions of times and prompt+context would bloat your token sequence beyond efficiency. For example, if a manufacturing company needs to call an LLM one million times monthly to format data consistently, fine-tuning eliminates the need for lengthy system prompts, reducing token overhead by 90%. At that scale, fine-tuning's up-front cost (millions of won) amortizes favorably against repeated inference costs. Before fine-tuning, you must already have fine-tuned the base model during post-training—a process involving supervised learning and reinforcement learning to align outputs with human expectations.
The critical insight: most problems should start with prompts, move to RAG if recency matters, and only progress to fine-tuning if you're operating at genuinely large repetitive scale.
結論
LLM literacy means understanding the complete pipeline: how massive text corpora become tokens, how parameters encode learned patterns, and how inference generates outputs through attention and sampling. This foundation lets you make strategic decisions about prompts, RAG, and fine-tuning based on actual problem requirements rather than chasing every new technique. As AI capabilities continue to evolve, this core understanding remains your most reliable guide.
원문출처: https://www.youtube.com/watch?v=geY4UO23QA8
powered by osmu.app