01Generative AI
LLMs & Prompt Engineering
Large Language Models predict the next token — that's it. Understanding that simple mechanism explains both their power and their limits.
How an LLM actually works
An LLM breaks text into tokens and, given the tokens so far, predicts the most likely next one — then repeats. It learned these probabilities from vast text using the Transformer architecture, whose 'attention' mechanism lets it weigh how every word relates to every other. There's no database of facts inside; it's pattern completion.
Prompt engineering
The prompt is your program. Small changes in how you ask change the output dramatically. The reliable patterns: give the model a role, be specific about the task and format, and show examples.
- Zero-shot — just ask. Few-shot — include 2–3 examples of the desired output.
- Chain-of-thought — ask it to 'think step by step' for reasoning tasks.
- Set role, context, task, and output format explicitly to reduce ambiguity.
Fine-tuning vs. prompting
Prompting adapts a model at request time — fast and free to iterate. Fine-tuning retrains the model on your examples to bake in a style or task — powerful but costly. Rule of thumb: try prompting (and RAG) first; fine-tune only when you need consistent behavior prompting can't reach.
Test yourself An LLM confidently cites a research paper that doesn't exist. Why, and what's the fix?
It predicts plausible tokens, not facts, so it can fabricate confident-sounding details (hallucination). The fix is grounding: give it the real source text via RAG and instruct it to answer only from that, with citations.
Models & techniques — what, when & why
Ask directly (zero-shot) or include 2–3 examples of the desired output (few-shot).
Your first tool for any task — before considering fine-tuning.
Examples anchor the model's format and style with no training cost.
Example: Show two labeled reviews, then ask it to label the third.
Instruct the model to reason step by step before giving a final answer.
Multi-step reasoning: math, logic, planning.
Working through steps sharply improves accuracy on complex problems.
Example: 'Let's think step by step' before a word problem's answer.
Retrains a base model on your own examples to bake in a task or style.
When prompting/RAG can't reach consistent behavior you need at scale.
Bakes behavior into the weights — powerful, but costs data, compute and upkeep.
Example: Fine-tune to always answer in your brand's tone and JSON schema.
Key takeaways
- LLMs predict the next token via Transformer attention — pattern completion, not a fact store.
- The prompt is the program: use roles, specifics, examples, and step-by-step reasoning.
- Prefer prompting/RAG first; fine-tune only for behavior you can't prompt into place.