By the end of this lesson you will be able to:
- Tell apart the main kinds of models: by output, by openness and by size.
- Choose a model using quality, cost, speed, privacy and context window.
- Pick the right way to improve results: prompting, RAG or fine-tuning.
- Compare two models fairly with a small test set, in Python.
There is no single "best" model
Our study-buddy startup now has a decision to make. Should it use the most powerful model available, a cheaper small one, or an open-source model it hosts itself? Every option is "best" at something. A model that writes beautiful essays may be too slow and expensive to answer 50,000 quick doubts a day. A tiny model that runs on a phone may struggle with Class 12 physics.
Choosing well starts with knowing the landscape.
Kinds of models
By what they produce
- Text and chat models answer questions, write and reason in language. These are the LLMs most people mean.
- Code models are tuned to write, explain and fix code.
- Image models create images from text (we build with these in Lesson 9).
- Speech models turn speech into text and text into speech, which is great for students who prefer listening.
- Embedding models turn text into lists of numbers that capture meaning. They power search and RAG (Lessons 8 and 15).
- Multimodal models take several kinds of input at once, for example a photo of a handwritten maths problem plus a question about it.
Foundation models
A foundation model is a very large model trained on broad data that can be adapted to many tasks. Most LLMs you use through an API are foundation models that were further trained to follow instructions and chat politely.
Proprietary vs open models
Proprietary (closed)
Examples: OpenAI's GPT models, Anthropic's Claude, Google's Gemini. You use them through an API.
✓ Usually the strongest quality, nothing to host
✗ Pay per token, data leaves your servers, you can't change the model
Open (open-weight)
Examples: Meta's Llama, Mistral, Qwen, Google's Gemma, Microsoft's Phi. You download and run them.
✓ Full control, data stays with you, can be fine-tuned freely
✗ You run the servers (GPUs) and handle scaling and safety
Read the licence. "Open" models come with different licences. Some allow any commercial use, others add conditions. Check before you ship a product on one.
Big vs small
Model size is measured in parameters, the numbers learned during training. Bigger models are generally smarter but slower and costlier. Small language models (SLMs) with a few billion parameters can run on a laptop or even a phone, which is great for offline apps and privacy. Lesson 19 is all about them.
Choosing a model: five questions
- Quality: is it good enough on your task? Test it on your own examples, not just public leaderboards.
- Cost: what does a typical request cost in tokens, times your daily volume?
- Speed (latency): students won't wait 20 seconds for a one-line answer.
- Privacy and control: can the data leave your servers? Do you need to run offline?
- Context window and language: can it read a whole chapter at once? Does it handle Hindi, Tamil or Bengali well enough?
Pick what matters for your product below and see which kind of model rises to the top.
Making a model better for your task
Once you have picked a model, you can improve its answers in four ways. They are ordered from cheapest and fastest to most expensive. Always start at the top and move down only when you have to.
- Prompt engineering (Lessons 4 and 5): clearer instructions, context and examples. Free and instant, and it often fixes most problems.
- Retrieval-augmented generation, RAG (Lesson 15): look up the relevant pages from your own material (say, the NCERT textbook) and put them in the prompt. Best when answers must come from your up-to-date documents.
- Fine-tuning (Lesson 18): train the model further on hundreds or thousands of your examples. Best for a consistent style or format, or a narrow specialised task.
- Training from scratch: only for very large organisations with unique data and huge budgets.
Study buddy decision. Students ask about their syllabus, which changes every year. So: a strong hosted model + RAG over the current textbooks for answers, and a small model for quick tasks like checking whether a question is about studies at all. No fine-tuning yet: prompts and RAG come first.
Where models run
You will meet the same models in different places:
- Provider APIs (OpenAI, Anthropic, Google): the simplest way to start.
- Cloud platforms (Azure AI Foundry, AWS Bedrock, Google Vertex AI): many models behind one account, with enterprise security and billing in your own cloud region.
- Hugging Face: the biggest hub of open models and datasets (Lesson 16).
- Your own machine: tools like Ollama or LM Studio run open models locally.
Hands-on: compare two models fairly
Professionals don't pick a model by gut feeling. They build a small evaluation set: real questions with known good answers. Then they score each model. Below are made-up answers from two models to four student questions.
Your task: the scorer is too strict. " Oxygen. " and "oxygen" should count as the same answer. Complete normalise() so it lowercases the text and strips spaces and full stops, then run it. It should print Winner: Model B.
tests = [
{"q": "Gas released in photosynthesis?", "answer": "oxygen"},
{"q": "Capital of Telangana?", "answer": "hyderabad"},
{"q": "7 x 8 = ?", "answer": "56"},
{"q": "Author of 'Wings of Fire'?", "answer": "apj abdul kalam"},
]
model_a = ["oxygen", "hyderabad", "54", "Rabindranath Tagore"]
model_b = [" Oxygen. ", "Hyderabad.", "56", "APJ Abdul Kalam"]
def normalise(text):
# TODO: lowercase, then remove spaces at both ends and any full stops
return text
def score(answers):
correct = sum(normalise(a) == t["answer"] for a, t in zip(answers, tests))
return correct / len(tests)
a, b = score(model_a), score(model_b)
print(f"Model A: {a:.0%} Model B: {b:.0%}")
print("Winner:", "Model A" if a > b else "Model B" if b > a else "Tie")
Show solution
def normalise(text):
return text.lower().strip().strip(".").strip()
Your task: estimate what a model would cost per month. The prices below are example numbers only. Replace them with the real prices from your provider's pricing page, then change the traffic numbers to match your app.
# Example prices in US dollars per 1 million tokens (NOT real prices: check your provider)
price_input_per_million = 0.50
price_output_per_million = 1.50
questions_per_day = 5000
input_tokens_per_question = 300 # prompt + context
output_tokens_per_question = 200 # the answer
days = 30
input_tokens = questions_per_day * input_tokens_per_question * days
output_tokens = questions_per_day * output_tokens_per_question * days
cost = (input_tokens / 1_000_000) * price_input_per_million + (output_tokens / 1_000_000) * price_output_per_million
print(f"Tokens per month: {input_tokens + output_tokens:,}")
print(f"Estimated cost per month: ${cost:,.2f}")
Check your understanding
Your app must answer from this year's updated syllabus PDFs. What should you try first after good prompting?
- Train a model from scratch
- Fine-tune on old question papers
- RAG over the syllabus documents
- Use a higher temperature
RAG puts the relevant, current pages into the prompt at question time, so updating the PDFs updates the answers. No retraining needed.
A hospital wants patient notes to never leave its own servers. Which option fits best?
- A hosted proprietary API
- An open model hosted on its own servers
- Any model with a high temperature
- A public chatbot website
Self-hosting an open model keeps data on the hospital's own infrastructure.
What is the most reliable way to choose between two models for your app?
- Score both on a set of your own real questions with known answers
- Pick the one with more parameters
- Pick the newest one
- Ask each model which one is better
A small evaluation set built from your own task shows real performance. Size, release date and the models' opinions of themselves don't.
Key takeaways
- Models differ by output type, openness and size. There is no universal best.
- Choose with five questions: quality on your task, cost, speed, privacy and context or language.
- Improve in order: prompt engineering → RAG → fine-tuning → training from scratch.
- Evaluate with your own test set, not guesses.
Next: power brings responsibility. Lesson 3 shows how to build generative AI that is safe and fair.
Your progress is saved in this browser.
Adapted from Lesson 2 of Microsoft's "Generative AI for Beginners" (MIT License), rewritten and extended by Aiprojects4U. View source