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.
The Art of AI Product Development ebook for free