Overview

5 Exploring and evaluating language models

This chapter lays a practical foundation for using language models in products, framing the discussion through Alex, a founder racing to build a content-generation MVP that is accurate, on-brand, and cost-efficient. It explains what LMs can and cannot do, how their capabilities shape user experience, and why product leaders must define objectives, align technology with user needs, and manage risks such as bias and hallucinations. The narrative emphasizes trade-offs—capability versus cost, speed versus control, and flexibility versus reliability—while positioning customization and evaluation as the keys to delivering user and business outcomes.

Core concepts include how training data determines strengths and limitations (scale and diversity, bias, data quality, knowledge cutoffs, privacy) and how pretraining objectives shape behavior: sequence-to-sequence for transformation tasks, autoregression for generation and conversation, and auto-encoding for analytical understanding. The chapter clarifies hallucinations and mitigation strategies, then shows how to expand capabilities through instruction tuning, supervised fine-tuning, and Retrieval-Augmented Generation. It compares three usage patterns—direct user interaction, programmatic outputs (function calling, Text2SQL), and predefined or offline tasks—highlighting risk controls such as guardrails, routers and cascades, schema-constrained generation, and post-hoc validation to ensure safe, structured outputs.

The LM landscape is mapped across major categories—mainstream commercial services, open-source models, reasoning models, small language models, and multimodal systems—each with distinct trade-offs in cost, control, performance, and deployment complexity. The chapter proposes an iterative lifecycle: constrain choices by governance and strategy, prototype with suitable models, evaluate using public benchmarks plus custom, outcome-based metrics (e.g., brand alignment, readability, accuracy, creativity, and relevance), and then tailor with prompting, RAG, and fine-tuning. Once in production, teams collect user feedback, track business impact, and continuously optimize with better data, targeted techniques, and MLOps—often converging on multi-model setups that balance performance and efficiency across use cases.

Mistral, which was trained with the “raw” objective of language modeling, fails to pick up the conversation.
ChatGPT was fine-tuned to engage in human-like conversations.
The objective of language modeling is to predict words based on their context
Words can have semantic relationships with both following and preceding words.
Three common LM usage patterns
Direct exposure of a language model to a user
The LM router analyzes the user request and sends it to the most suitable model (or, optionally, a human agent).
In an LLM cascade, a user is sent from one model to another until one of the models outputs a highly confident answer.
LMs can generate code automatically executed by downstream components.
LMs can be used for offline processing, which allows running additional validation of their outputs.
DeepSeek discloses its reasoning process to the user.
The iterative process of developing with LMs
Evaluation of some Llama 3 variants using public benchmarks
When evaluating your language model, you need to consider the trade-off between speed and reliability.
Three primary techniques for LM customization, by growing technical difficulty and depth

Summary

  • Before integrating LMs in your application, familiarize yourself with their inner workings, the available options, and core capabilities to inform your design and deployment decisions.
  • Choose a model based on trade-offs like quality, cost, governance, and scalability, prioritizing factors that match project goals.
  • Treat the LM lifecycle as a flexible, iterative process, adapting development flow to meet changing user expectations and project stakes.
  • Use standardized benchmarks (e.g., MMLU, SQuAD) to gauge model performance, especially in the early stages.
  • Develop tailored evaluation metrics (e.g., brand alignment, readability, accuracy) to ensure the LM meets specific user needs.
  • Use prompt engineering for immediate adjustments, Retrieval-Augmented Generation (RAG) for accuracy, and fine-tuning for personalized output.
  • Monitor training data for potential biases and inaccuracies, setting up mechanisms to identify and mitigate harmful outputs before deployment.
  • Apply LMs in specific, well-defined backend tasks when direct user interaction is unnecessary, improving reliability and control.
  • Implement feedback mechanisms like thumbs-up/thumbs-down ratings and user satisfaction metrics to refine the model post-deployment.
  • Continuously refine your data, adding corrective examples to align model outputs with evolving trends and expectations; effective data management (DataOps) is essential.
  • Your engineers should regularly explore new academic and technical advancements, identifying techniques to improve performance.
  • Automate data monitoring, error tracking, and model updates through a structured MLOps pipeline to speed up iteration cycles and align the model with user needs.

FAQ

What’s the difference between LMs, LLMs, and SLMs?“Language model” (LM) is the umbrella term. Large language models (LLMs) typically have 2B+ parameters and offer broad, versatile capabilities but are costly and heavy. Small language models (SLMs) have fewer than ~2B parameters; they’re faster, cheaper, and ideal for focused tasks where deep general knowledge isn’t required.
How does training data shape a model’s capabilities and risks?Training data determines what a model can do and where it fails. Key factors: scale and diversity (breadth vs depth), bias (societal stereotypes can surface), data quality/noise (misinformation leaks through), knowledge cut-off (no awareness after a certain date), and privacy/IP concerns. Always review model cards/papers to understand these trade-offs and plan mitigations.
Which pre-training objectives exist and which tasks do they suit?Three common objectives: 1) Autoregressive (e.g., GPT-family) predicts next tokens; excels at generation, dialogue, summarization. 2) Auto-encoding (e.g., BERT) reconstructs masked tokens using both sides of context; strong for analytical tasks like classification, NER, and sentiment. 3) Sequence-to-sequence (encoder-decoder; e.g., BART) transforms input sequences; strong for translation, summarization, and code generation. Chat-style models add RLHF to behave helpfully and safely.
Why do LMs hallucinate and how can we reduce it?Hallucinations arise because LMs predict plausible text rather than retrieve ground truth. Causes include noisy/conflicting training data and lack of structured knowledge. Mitigations: Retrieval-Augmented Generation (RAG) for grounding, targeted fine-tuning (including “memory” fine-tuning for hard facts), fact-checking and post-validation, and human-in-the-loop reviews for high-stakes outputs.
What are the main usage patterns for LMs and their risk profiles?Three patterns: 1) Direct user interaction: maximum flexibility but high risk (unbounded inputs/outputs); needs strong guardrails and latency control. 2) Programmatic use: LM outputs code/JSON for downstream execution; structured but risky if incorrect code is executed—require schema enforcement, validation, and strict permissions. 3) Predefined/offline tasks: controlled inputs, structured outputs, extra validation possible; safest but less real-time flexibility.
When should I use model routers or cascades?Use routers to send a request to the most suitable model (e.g., cheap SLM for simple queries, premium LLM for complex ones). Use cascades to try models in sequence—from simpler/cheaper to more capable—until confidence is high. Both patterns cut cost and improve reliability; they pair well with human fallbacks and can deliver large savings (e.g., FrugalGPT reports up to ~98% cost reduction in some settings).
How do I choose among commercial, open-source, reasoning, small, and multimodal models?- Mainstream commercial (LLMaaS): fastest path to value and broad capability; expensive; limited deep customization; consider for prototyping and general tasks. - Open-source: full control and privacy; infra and MLOps heavy; best for custom moats. - Reasoning models (e.g., o1/o3/DeepSeek-R1): better multi-step problem solving; slower and costlier; use for logic-heavy applications. - SLMs: fast and economical for simpler, repetitive tasks. - Multimodal: needed when combining text with images/audio/video; heavier to deploy.
How should I evaluate candidate models effectively?Combine public benchmarks with custom evaluation. Benchmarks: MMLU, HELM, ARC, SQuAD for general QA/language skills; Spider (Text2SQL) or function-calling leaderboards for programmatic tasks. Then build a custom framework with human and LLM-assisted reviewers to measure outcomes like accuracy, contextual relevance, brand alignment, readability, and creativity. Balance speed (automation) with reliability (human review) and set acceptance thresholds.
What are the main ways to customize a model for my product?Three escalating techniques: 1) Prompt engineering to steer tone, structure, and task framing. 2) RAG to ground outputs in up-to-date, trusted data (client docs, knowledge bases). 3) Fine-tuning to internalize brand voice, domain style, and task formats for consistent, on-tone outputs. In practice, combine them: prompt templates + RAG for accuracy, fine-tuning for voice and consistency.
What does the LM lifecycle look like and how do I keep improving?Iterative loop: select models (within governance and infra constraints), customize (prompting, RAG, fine-tuning), evaluate (benchmarks + custom metrics), deploy, collect real-world feedback (UX signals, thumbs up/down, satisfaction, conversion), and continuously optimize. Improve via better data (add failure cases, update knowledge), advanced techniques (search, parameter-efficient fine-tuning), and automate with MLOps/LLMOps for rapid iteration.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Art of AI Product Development ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Art of AI Product Development ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Art of AI Product Development ebook for free