Large Language Models (LLMs) have rapidly become the backbone of today’s AI systems — powering everything from chatbots and AI assistants to search engines, code generators, and automation tools. However, for engineers stepping into this field, the learning process can feel overwhelming and scattered. Key ideas like tokenization, attention mechanisms, fine-tuning, and evaluation are often taught separately, making it difficult to build a unified understanding of how all the pieces connect.
I experienced this challenge myself when shifting from computer vision to working with LLMs. In a brief period, I needed to grasp not only the theoretical foundations of transformers but also the hands-on realities: trade-offs during training, bottlenecks at inference time, difficulties in alignment, and common evaluation mistakes.
This article aims to close that gap.
Instead of going deep on any one topic, it offers a structured overview of the LLM engineering landscape — highlighting the essential building blocks you need to know in order to design, train, and deploy real-world LLM applications.
We’ll progress from the basics of text representation, through model architectures and training approaches, all the way to inference optimization, evaluation techniques, and system-level concerns — including practical topics like prompt engineering and minimizing hallucinations.
By the time you finish reading, you should have a solid mental framework for understanding how modern LLM systems are constructed — and where each concept fits into the bigger picture.
Turning Text into Numbers

Tokenization
When preparing data for a model, we can’t simply feed it raw letters or words — we need a method to convert text into numerical form. A natural first thought might be to assign every word in the language a unique number and pass those numbers to the model. But English alone contains hundreds of thousands of words, and working with such a massive vocabulary would be impractical from both a memory and efficiency standpoint.
So what’s the alternative? We could try encoding individual characters, since the English alphabet has only 26 letters. But that introduces its own issues — models would find it hard to extract meaning from single characters alone, and input sequences would grow excessively long, complicating the training process.
The practical answer is tokenization. Rather than operating at the word or character level, we break text into the most frequently occurring and meaningful subword units. These subwords serve as the model’s vocabulary building blocks: common words stay intact as single tokens, while uncommon words get split into combinations of smaller subword pieces.
A widely used algorithm for this is Byte-Pair Encoding (BPE). BPE begins with individual characters as tokens, then iteratively merges the most common pairs of tokens into new ones, gradually constructing a vocabulary of subword units until a target vocabulary size is reached.
At this point, each token is given a unique number — its ID within the vocabulary.
Embeddings
Once the data has been tokenized and each token has an ID, we need to attach semantic meaning to those IDs. This is done through text embeddings — mappings that convert discrete token IDs into continuous vector spaces. In this space, tokens with similar meanings are positioned near each other, and even arithmetic operations can reveal semantic relationships (for example: embedding(queen) − embedding(woman) + embedding(man) ≈ embedding(king)).
Typically, embedding layers are trained to accept token IDs as input and output dense vectors. These vectors are optimized alongside the model’s training objective (such as next-token prediction). Over the course of training, the model learns embeddings that capture both syntactic and semantic properties of words, subwords, or tokens. Well-known embedding models include word2vec, GloVe, and BERT.
Positional Encoding
In general, LLMs don’t inherently understand the structure of language. Natural language is sequential — the order of words matters — yet tokens that are far apart in a sentence can still be closely related. To account for both local ordering and long-range dependencies, we inject positional information about the tokens into each embedding.
There are several common approaches to positional encoding:
- Absolute positional encodings — Fixed patterns, such as sine and cosine functions at varying frequencies, are added to token embeddings. This is straightforward and effective but can struggle with very long sequences, since it doesn’t explicitly capture relative distances.
- Relative positional encodings — These encode the distance between tokens rather than their absolute positions. A popular technique is RoPE (Rotary Positional Embeddings), which represents position through vector rotations. This method scales more gracefully to longer sequences and captures relationships between distant tokens more naturally.
- Learned positional encodings — Instead of using fixed mathematical functions, the model learns position embeddings directly during training. This offers flexibility but may not generalize as well to sequence lengths not encountered during training.
Model Architecture

After the data has been tokenized, embedded, and enriched with positional encodings, it flows through the model. The current state-of-the-art architecture for processing text is the transformer architecture, whose core is built on the attention mechanism. A transformer is typically made up of a stack of transformer blocks:
- Multi-Head Attention: Allows the model to attend to different parts of the input sequence at the same time, capturing diverse contextual information. It computes Queries (Q), Keys (K), and Values (V) to define relationships between words.
- Position-wise Feed-Forward Network (FFN): A fully connected network applied independently to each position, introducing non-linearity.
- Web-based data frequently includes extraneous elements like advertisements, navigation bars, headers, and footers, plus technical noise generated by HTML, CSS, and JavaScript. These pages may also feature replicated content, spam, text of poor quality, or material that is potentially harmful.
- Literary works may bring in complications such as metadata (like publisher details, page numbers, and footnotes), errors caused through OCR digitization, and passages that repetitively vary in style. Furthermore, issues of copyright require strict filtering and adherence to licensing terms.
- Code repositories may contain automatically generated files, repetitive copies, an abundance of comments, or standardized code blocks. Adhering to licenses is crucial, and low-quality or erroneous code can damage the training process if it is not eliminated.
- Low Rank Adaptation (LoRA) is a very common strategy. Rather than modifying the entire weight matrix, LoRA learns two smaller, low-rank matrices, A and B, where their product serves as an approximation of the changes to the initial weights. While the original pre-trained weights stay stationary, only A and B are adjusted. This significantly increases the efficiency of fine-tuning concerning memory and computation, all while maintaining strong results. (See also: practical LoRA training techniques and best practices.)
- Additional parameter-efficient options include prefix tuning, where a small collection of trainable “virtual tokens” are attached to the input and adjusted during the training process. Another method involves adapter layers, which are small, trainable segments added in between existing transformer blocks while the primary structure of the model remains frozen.
- Dialogue data: carefully selected human-to-human or human-to-AI conversations designed to teach the model to reply naturally during interactive exchanges.
- Instruction data: sets of prompts paired with appropriate responses, allowing the model to master the art of following directions, answering questions, and carrying out reasoning or particular task-based actions.
- Gather preference data: Typically, humans provide the gold standard by ranking various responses generated by the model for a single prompt (for example, identifying which response is more useful or safer), creating relative preferences rather than absolute labels. Nonetheless, in some situations, stronger models may be used to create preference data or provide critiques of weaker models, thus lowering the dependence on costly human labeling. In real-world applications, blending human and automated feedback enables scaling while still maintaining high quality.
- Train a reward model (RM): A separate model is constructed to evaluate responses based on human preferences. When given a prompt and a possible answer, the reward model provides a numerical score reflecting the quality of that answer according to human standards.
- Optimize the policy (the LLM): The language model is then refined to maximize the reward signal, essentially learning to produce outputs that humans are statistically more likely to favor.
- Proximal Policy Optimization (PPO): PPO updates the model while limiting how drastically it can diverge from the original policy during a single update, thereby preventing instability or a decline in the quality of the generated text. A detailed video explanation of PPO can be found here.
- Direct Preference Optimization (DPO): This method eliminates the requirement for a distinct reward model. Instead, it optimizes the model to favor selected responses over rejected ones via a classification-style objective, simplifying the pipeline and lowering the total training complexity.
- Group Relative Policy Optimization (GRPO): A specialized variant that evaluates groups of outputs instead of simple pairs, enhancing stability and sample efficiency by utilizing more comparative data.
- Kahneman-Tversky Optimization (KTO): KTO accounts for asymmetric preferences, such as imposing harsher penalties for poor outputs than rewards for good ones, which can more accurately mirror human judgment in scenarios critical to safety.
- Offline RL (dominant today): The model is trained on a fixed dataset of
- Offline RL: The model learns from a fixed dataset of human preferences without any additional interaction. Once the preference data is gathered and the reward model is built, policy optimization (such as PPO or DPO) is carried out on this static dataset.
- Online RL: The model continuously engages with its environment—such as users or human evaluators—producing new responses and receiving real-time feedback that is fed back into training. This establishes a dynamic loop where the model can explore and refine its performance over time.
Reasoning-aware RL (e.g., RL through Chain-of-Thought)
RL can also enhance reasoning capabilities. Rather than rewarding only final answers, the model can be incentivized to generate clear, logical intermediate reasoning steps (chain-of-thought). This promotes more organized, transparent, and dependable problem-solving.Hallucination in LLMs

Image generated with Gemini Even when trained on accurate data, large language models often generate false or fabricated outputs—a phenomenon known as hallucination. This occurs because LLMs are probabilistic systems that predict the next word based on patterns in their training data and prior context, rather than retrieving verified facts. Fortunately, several strategies can help reduce hallucinations:
Retrieval Augmented Generation (RAG): Integrate external knowledge sources during inference so the model can pull in up-to-date, factual information and base its responses on reliable data instead of relying solely on internal knowledge, which may be outdated or incomplete. RAG systems are often complex and typically involve:
- Chunking: Breaking documents into smaller, focused segments before indexing. Effective chunking strikes a balance—too large, and relevance gets diluted; too small, and critical context is lost.
- Embedding: Transforming text chunks into dense numerical vectors that capture meaning. In RAG, both user queries and document chunks are mapped into the same vector space, enabling semantic similarity searches even without exact keyword matches.
- Retrieval: Ensuring the system fetches relevant, diverse, and non-redundant chunks to pass to the model. Success depends on embedding quality, chunking approach, indexing method, and search settings.
- Reranking: A follow-up step that reorders the initially retrieved chunks using a more accurate (but often slower) model. While initial retrieval prioritizes speed, rerankers emphasize relevance, helping surface the most useful context for generating a response.
Training to say “I don’t know”: Teach the model to recognize and express uncertainty when it lacks sufficient information, preventing it from inventing plausible but incorrect answers.
Exact matching and post-evaluation: Apply strict verification—either against trusted sources or using external model-based evaluators—during or after generation to ensure outputs align with factual references, especially for high-stakes or precise content.
Optimization

Image generated with Gemini Training LLMs is already a major challenge—it demands vast numbers of GPUs to store the model, gradients, and optimizer states. But inference is equally demanding: serving millions of user requests quickly and with high quality is crucial for user retention.
Training optimization
Large models are typically trained using stochastic gradient descent (SGD) or a variant. Instead of updating parameters after every example, gradients are computed over batches of data, improving stability and efficiency. Larger batches generally yield more accurate gradient estimates, though excessively large ones can hinder convergence or require careful tuning.
For massive models like LLMs, a single GPU can’t hold all parameters or process large batches alone. Training is therefore distributed across multiple GPUs or even entire clusters. This requires smart decisions about how to divide the workload—by splitting the data, the model parameters, or the computation pipeline.
While distributed training is well-established in deep learning, LLMs pose unique challenges due to their scale and memory demands. Several key strategies have emerged:
- Data parallelism: Each GPU holds a full copy of the model but processes different data batches; gradients are then averaged across devices.
- Model parallelism: The model’s parameters are split across GPUs, with each device handling a portion of the model.
- Pipeline parallelism: Different model layers are assigned to different GPUs, and data flows through them sequentially like stages in an assembly line.
- Tensor parallelism: Even individual operations (like large matrix multiplications) are divided across multiple GPUs.
- DeepSpeed / ZeRO: A framework and suite of techniques designed to train large models more efficiently by partitioning optimizer states, gradients, and parameters to minimize memory usage.
In all these approaches, two goals are balanced: minimizing communication between GPUs (e.g., for gradient synchronization) while maximizing the amount of useful data each GPU can process. Additional techniques to save memory and boost training speed include:
- Gradient checkpointing: A memory-saving method that stores only select intermediate activations during the forward pass and recomputes the rest during backpropagation. This trades extra computation for significantly reduced GPU memory use, enabling training of larger models or longer sequences.
Here is the paraphrased version of your article. The HTML structure is preserved, but the text has been rewritten for clarity and readability:
- Mixed precision training: Employs lower-precision numerical formats (such as FP16 or BF16) for most calculations, while maintaining critical components (like master weights and accumulation buffers) in higher precision (FP32). This approach cuts down memory consumption and accelerates training, particularly on modern GPUs equipped with dedicated hardware, with negligible effect on accuracy.
Inference Optimization
- Distillation: Large models frequently contain more parameters than necessary, so we can train a compact student model to replicate a larger teacher model. Rather than simply learning the correct outputs, the student replicates the teacher’s complete probability distribution—including less probable tokens—thereby capturing more nuanced relationships. This produces performance close to the teacher’s in a significantly smaller and faster model.
- Flash-attention: A refined attention algorithm that calculates exact attention while substantially cutting memory requirements. It sidesteps creating the full attention matrix by breaking computations into tiles and merging operations into a single GPU kernel, keeping data in high-speed on-chip memory. The outcome: markedly faster training and inference, particularly for extended sequences, and the ability to handle longer context windows without altering the model.
- KV-caching: When generating text token by token, recalculating attention over previously seen tokens is inefficient. KV-caching retains previously computed keys and values and reuses them for subsequent tokens. This brings generation complexity down from quadratic to linear relative to sequence length, substantially accelerating long-form text generation.
- Pruning: Neural networks frequently have excess parameters, so pruning eliminates unnecessary weights. This can be structured (removing whole neurons, attention heads, or layers) or unstructured (removing individual weights). In real-world applications, structured pruning is favored because it maps more naturally to hardware, making the performance gains practically achievable.
- Quantization: Lowers numerical precision (for instance, from 32-bit floating point to 8-bit integers) to compress models and accelerate computation. It decreases memory footprint and boosts efficiency on specialized hardware. Whether applied post-training or during training, it may cause a slight dip in accuracy, but careful calibration keeps this to a minimum. Successful quantization also depends on managing value ranges (such as keeping activation magnitudes small) to prevent information loss.
- Speculative decoding: Accelerates generation by leveraging two models: a lightweight, speedy draft model and a larger, precise target model. The draft model predicts several tokens ahead, and the target model validates them in parallel—accepting correct predictions and recalculating any that don’t match. This enables producing multiple tokens per step rather than just one.
- Mixture of experts (MoE): Rather than engaging all parameters for every token, MoE models maintain many specialized “experts” and use a gating mechanism to activate only a handful per input. This allows for enormous model capacity without a corresponding increase in computational cost. Prominent examples include Switch Transformer, GLaM, and Mixtral.
For those interested in more advanced methods, NVIDIA’s detailed blog on inference optimization is an excellent resource.
Prompt engineering

Image generated with Gemini Prompt engineering is a fundamental aspect of working with LLMs because, in practice, the model’s behavior is shaped not only by its trained weights but by how it is guided during inference. The same model can yield vastly different outputs depending on how instructions, context, and constraints are phrased.
Prompt engineering is not a one-time task—it’s an iterative process. Minor adjustments in wording, sequence, or constraints can lead to significant shifts in behavior. Treat prompts like source code: test them, measure results, refine continuously, and version-control them as part of your workflow.
What makes a strong prompt
- Be explicit about the task, not just the topic: A vague prompt asks what you want (“Explain RAG”). A strong prompt defines how you want it (“Explain RAG in 5 bullet points, focusing on failure modes, for a technical blog audience”).
- Separate instruction, context, and format: Effective prompts clearly distinguish between what the model should do, what information it should draw from, and how the output should be structured. For instance: instructions (“summarize”), context (retrieved passages), and format (“JSON with fields X, Y, Z”).
- Use examples (few-shot prompting): Supplying 1–3 examples of the desired input-output pattern greatly enhances reliability for complex tasks. This is particularly valuable for classification or structured formatting.
- Constrain output structure firmly: If you need machine-readable or consistent results, enforce strict formats (such as JSON or defined schemas).
- Manage context quality: More context isn’t automatically better. Irrelevant or noisy inputs can hurt performance. Focus on high-value information, and in RAG setups, make sure retrieval is accurate and well-filtered.
Practical considerations
- Track prompt changes like code. Document who made what change, when, and the reasoning behind it. This enables straightforward debugging and rollback.
- Use templates where feasible. Decompose prompts into reusable building blocks (instructions, context placeholders, formatting rules).
- Implement routing systems. Dynamically adjust both the model selection and the prompt based on the nature of user requests.
- Establish structured testing. Run prompts against a benchmark dataset and evaluate outputs using metrics or structured rubrics (correctness, completeness, style).
- Keep a human in the loop. For subjective qualities such as clarity or reasoning quality, human reviewers remain the most dependable evaluators—particularly for edge cases.
- Maintain a test suite of critical examples, with a focus on safety.
- Conduct red teaming—actively attempting to bypass the safeguards you’ve put in place is now standard industry practice.
Evaluation

Image generated with Gemini Large language models are deployed across a broad spectrum of tasks—from structured question
When it comes to open-ended text generation, there’s no single, universal scorecard—no one-size-fits-all metric that captures everything. In reality, how you evaluate a model depends deeply on the specific task at hand. Still, most evaluation strategies fall into two main camps: classic statistical measures and newer LLM-powered judges.
No matter which metrics you choose, one thing stays constant: the evaluation dataset is your anchor for what counts as a “good” response. It must be varied, accurate, grounded in real-world scenarios, and aligned with the exact tasks your model is built to handle.
Classic Metrics
These rely on surface-level word and phrase comparisons. They’re straightforward to code and run quickly, but they fall short when it comes to capturing deeper meaning.
- Levenshtein distance counts how many single-character edits—adds, deletes, or swaps—are needed to convert one string into another.
- Perplexity gauges how confident a model is in predicting a given text sequence; the lower the perplexity, the better the fit.
- BLEU measures how closely a candidate translation matches a reference by counting shared n-grams, prioritizing precision over recall.
- ROUGE focuses on recall for summarizations and generated content, looking at how much of the reference text is captured via overlapping n-grams and sequences.
- METEOR goes a bit further by matching exact words, stems, and synonyms, then balancing precision and recall into a single score.
LLM-Powered Evaluators
- BertScore leverages contextual embeddings from BERT to assess semantic similarity instead of exact wording. It excels at spotting paraphrases and nuanced rephrasing, making it well-suited for summarization and translation evaluations.
- GPTScore calls on a large language model to reason about qualities like correctness, relevance, coherence, or tone, all without needing a reference answer. It fits open-ended or subjective tasks where there’s no clear right answer.
- SelfCheckGPT has the model critique its own outputs, flagging hallucinations, logical gaps, or misleading claims. This is especially handy when external fact-checking is costly or impractical.
- Bleurt is a BERT-derived metric fine-tuned specifically for evaluation. It uses learned semantic representations to deliver a single quality score that reflects fluency, fidelity to the original meaning, and paraphrase detection.
- GEval works by feeding the model a scoring rubric—such as “rate factual accuracy” or “judge clarity”—and returning a structured score or detailed feedback. It shines in subjective settings where rigid metrics miss the mark.
- Directed Acyclic Graph (DAG) splits evaluation into a sequence of small, rule-governed checks. Each node acts as an independent LLM judge handling one specific criterion, and the flow between nodes determines the overall decision path. This stepwise structure cuts down ambiguity and boosts consistency for tasks that lend themselves to decomposition.
Keep in mind, LLM-based evaluators aren’t perfect—they bring their own quirks:
- Bias: Judge models might lean toward longer responses, certain phrasing styles, or outputs that mirror their training data.
- Variance: Because these models are probabilistic, small tweaks—like adjusting temperature—can yield different scores for identical inputs.
- Prompt sensitivity: Even slight changes to your rubric or prompt wording can meaningfully shift results, making cross-experiment comparisons tricky.
Think of LLM evaluation as an engineered system that requires careful tuning. Lock down your prompts, stress-test them thoroughly, and stay alert to hidden biases.
Stepping outside conventional use cases, there’s an entire family of metrics dedicated to evaluating RAG (Retrieval-Augmented Generation) pipelines, which break the process into separate retrieval and generation stages, and another set tailored specifically for summarization tasks.
For anyone wanting a thorough overview of LLM evaluation techniques, I’d highly recommend this survey paper covering a wide range of methods.
LLM-as-a-judge vs. traditional metrics: which should you use?
Not every output lends itself to hard-and-fast scoring rules. When you’re assessing things like summary quality, tone, helpfulness, or adherence to instructions, rigid metrics often miss the point. That’s where LLM-as-a-judge excels: rather than checking for exact word matches, you prompt a model to score responses against a defined rubric.
That doesn’t mean traditional metrics are obsolete. When you have a definitive correct answer—like verifying factual accuracy or exact phrases—they remain your fastest, cheapest, and most consistent option.
The most effective setups blend both approaches: lean on traditional metrics for objective correctness, and turn to LLM judges for subjective or open-ended quality.
Evaluation loops in production
Robust evaluation isn’t a one-shot thing—it’s layered:
- Offline metrics: Start by using labeled datasets and automated scoring to rapidly weed out underperforming model versions.
- Human evaluation: Loop in annotators or domain experts to catch nuance—realism, usefulness, safety, and edge cases that automated metrics overlook.
- Online A/B testing: Measure real-world performance metrics like clicks, retention, and satisfaction.
Once your system is deployed, evaluation is far from over—it’s an ongoing process. Continuously log user interactions, sample them, and review them closely. These real-world signals expose failure modes and evolving usage patterns. The more granular data you collect—model embeddings, full responses, latency figures—the richer your diagnostic toolkit becomes.
Even if the model itself stays exactly the same, its behavior and apparent performance can drift over time. Known as behavior drift, this slow degradation creeps in as the world changes around it: shifts in user queries, emerging slang, changes in domain emphasis, or even subtle tweaks to prompts and templates. The tricky part is that this decline is often quiet and gradual, easy to overlook until users start noticing the difference.
To detect drift early, closely monitor both what goes in and what comes out.
- Input: Watch for shifts in embedding patterns, query lengths, topic trends, or the emergence of new, unfamiliar tokens.
- Output: Keep an eye on changes in tone, response length, refusal frequency, or safety alerts. In addition to these direct indicators, track evaluation proxies over time—such as LLM-as-a-judge ratings, user feedback (like thumbs up/down), and task-specific heuristics—while accounting for seasonal user behavior. Set up alerts when statistical deviations go beyond acceptable limits.
LLM Criticism
A frequent critique of large language models is that they act like “information averages”: rather than storing or retrieving exact facts, they learn a smoothed-out statistical pattern across vast amounts of text. As a result, their responses often reflect the most probable blend of many possible continuations instead of a single, well-grounded truth. This can lead to answers that sound confident but are actually just high-probability word sequences—or overly generic replies that lack precision.
This behavior stems from the cross-entropy loss function, which trains models to minimize the gap between predicted token probabilities and the actual next token in training data. While great for producing fluent language, cross-entropy only measures how well the model matches likelihoods—not whether its output is true, logically consistent, or causally sound. It doesn’t distinguish between “sounds right” and “is correct”—only whether the next word fits the training distribution.
The real-world consequence? Optimizing for cross-entropy promotes mode-averaging, where the model favors safe, middle-ground predictions over sharp, verifiable ones. That’s why LLMs excel at fluent text generation but struggle with tasks demanding precise logic, long-term consistency, or factual accuracy—unless supported by external tools like retrieval systems or fact-checking mechanisms.
Summary
Developing and deploying large language models isn’t about nailing one big idea—it’s about understanding how dozens of interconnected systems work together to create coherent, useful intelligence. From tokenization and embeddings to attention-based architectures, and from pre-training to fine-tuning and reinforcement learning, each component plays a distinct role in transforming raw text into capable, controllable models.
What makes LLM engineering both challenging and rewarding is that no single piece determines success in isolation. Low-level optimizations like KV-caching, FlashAttention, and quantization are just as critical as high-level decisions about model design or alignment strategy. Likewise, real-world performance hinges not only on training quality but also on inference speed, evaluation methods, prompt engineering, and ongoing monitoring for drift and failures.
Taken as a whole, LLM systems resemble less a single model and more a dynamic stack: data pipelines, training objectives, retrieval modules, decoding techniques, and feedback loops—all operating in sync. Engineers who grasp this full stack can move beyond simply “using models” and start building systems that are robust, scalable, and aligned with real-world needs.
As the field advances—toward longer contexts, more efficient designs, stronger reasoning, and better human alignment—the central challenge remains unchanged: bridging the gap between statistical pattern matching and practical, reliable intelligence. Mastering that bridge defines the work of an LLM engineer.
Notable models in chronological order
BERT (2018), GPT-1 (2018), RoBERTa (2019), SpanBERT (2019), GPT-2 (2019), T5 (2019), GPT-3 (2020), Gopher (2021), Jurassic-1 (2021), Chinchilla (2022), LaMDA (2022), LLaMA (2023)
Enjoyed the author? Stay in touch!
If you found this article helpful, share it with a colleague! For more insights on machine learning and image processing, hit subscribe!
Think something’s missing? Feel free to leave a note, drop a comment, or reach out directly via LinkedIn or Twitter!
This process generally requires hundreds of billions to trillions of tokens sourced from a variety of materials, including web pages, books, articles, codebases, and conversational data.
To make informed choices regarding model size, training duration, and the volume of the dataset, scientists rely on LLM scaling laws. These laws clarify the relationships between these variables and assist in determining the ideal configuration for reaching peak performance.
Data pre-processing is an essential phase, as training a model directly on unrefined text can severely hinder its effectiveness. Training data is gathered from numerous locations, each presenting specific difficulties that require thorough cleaning and filtering.
In an effort to solve these issues, datasets are commonly filtered based on language, and quality and imbalances among different sources are rectified through data augmentation or by adjusting the weight of each source.
Supervised fine-tuning
During supervised fine-tuning, we do not generally update every single parameter of the model. Conversely, the vast majority of the pre-trained weights are left unchanged (frozen), and a limited number of extra parameters are taught. This is achieved by integrating lightweight adapter modules or by utilizing parameter-efficient techniques like LoRA, all while using a refined and clean subset of data for training.
From a broader standpoint, supervised fine-tuning serves as the stage where the model learns to act appropriately for a particular task by using top-notch, labeled examples. This usually involves:
All together, these methods ensure that a pre-trained model’s behavior is aligned with the results we desire when it is being used.
Reinforcement learning
While supervised fine-tuning teaches the model what it should do, reinforcement learning is employed to improve how successfully it does it, particularly for subjective or complex tasks like dialogue, logical reasoning, and safety.
Contrasting with supervised learning, which uses fixed targets, RL operates through a feedback loop where outputs from the model are evaluated, scored, and improved progressively. Consequently, RL is a vital instrument for aligning models with human preferences. Effectively, it works to: promote helpful, safe, and truthful behavior, decrease toxic, biased, or dangerous outputs, and boost conversational quality and adherence to instructions.
Because the data used for alignment is smaller in size yet superior in quality compared to pre-training data, RL acts as a refined steering mechanism rather than a source for gaining new knowledge.
A prevalent approach is Reinforcement Learning from Human Feedback (RLHF), which typically consists of three primary stages:
Refining the policy (LLM) can be a difficult task. Reinforcement learning can potentially erode previously acquired knowledge, or the model might default to predicting only a single high-reward response, failing to provide diversity. Numerous algorithms are utilized for this optimization to handle these challenges:
Reinforcement learning for language models can be broadly divided into online and offline categories depending on the collection and application of data throughout the training process:







