AI and language model fundamentals
Understanding learned behavior, language models and their practical limits.
Machine learning fits patterns from examples rather than specifying every rule by hand. Language models generate tokens from context, which can produce useful answers as well as plausible mistakes. Understanding training, inference, embeddings and context limits helps you choose between a model, a simpler rule or a human decision.
Why it matters for a product engineer
A language model predicts the next token from the tokens before it. That simple fact explains most of what it does well and most of what goes wrong. It knows what was in its training data, plus what you put in the context. It writes fluent text even when it has no good answer. Its context window has a limit, and even inside that limit, attention is not equal. Product engineers who understand this design better prompts, choose better data to send, and know when a rule or a person is the better choice.
How to do it
- Separate what the model must know from training, and what you must give it in the context.
- Count tokens for real inputs, and plan for the longest cases, not the average.
- Put the most important information at the start or the end of the context.
- Send fewer, more relevant documents instead of everything that might help.
- Compare the model with a simple baseline, such as a rule or a search, on the same test cases.
Common mistakes
- Treating the model as a database of facts.
- Assuming that a bigger context window means the model uses all of it well.
- Judging a model from a few good examples.
- Using a model where a fixed rule would be cheaper and always correct.
Example
In 2023, researchers at Stanford and elsewhere gave models a question and 20 documents, only one of which contained the answer. They moved that document to different positions. GPT-3.5-Turbo answered correctly 75.8% of the time when it was first, and 53.8% when it was in the middle. With no documents at all, it scored 56.1%. These were 2023 models, so test your own. The lesson is the same: where you put information can matter.
GPT-3.5-Turbo accuracy by position of the document with the answer, out of 20
- 1st document75.8%
- 5th document57.2%
- 10th document53.8%
- 15th document55.4%
- 20th document63.2%
- No documents56.1%
With the answer in the middle, the model did worse than with no documents at all.
MeasuredLiu et al., Lost in the middle, 2023
Sources: Lost in the middle: how language models use long contexts (Liu et al., TACL 2024) ↗ · Introduction to large language models (Google Machine Learning Crash Course) ↗
Technical leverage
Run small experiments that separate training from inference, expose token and context limits, and compare a model with a deterministic baseline.
Evidence of mastery
Put it into practice- Practice
- Compare a language model with a rule-based solution on a bounded classification task, including unfamiliar and ambiguous inputs.
- Artifact
- A reproducible notebook or script and a short decision on whether a model is justified.
What good looks like
- Explain what is learned, what is provided at inference and where errors arise.
- Report failures as well as successful examples; avoid claiming general reliability from a small sample.
Use this evidence to assess your work. Your map status is a self-assessment, not a certification.
Resources
1- courseStart here
Introduction to large language models ↗
Google Machine Learning Crash Course · 45 minExplains tokens, training, context and common model limitations; earlier modules cover the prerequisites.
Tools
2- ToolOpen source
- ToolOpen source
promptfoo
Open-source tool for testing prompts and models against test cases, and for red-teaming LLM apps.