Parameters: temperature, top_p and max tokens
Course contents (20 lessons)
- Getting to know Meta AI and Llama
- What Meta AI is and where you can use it
- Meta AI versus Llama: the assistant and the models
- Your first chat with Meta AI
- Prompt basics that work
- The anatomy of a good prompt
- Context, tone, length and follow-ups
- Everyday uses
- Writing and replying to messages
- Captions, posts and bios
- Planning and study help
- Customer replies for a small business
- Images, groups and privacy
- Writing image generation prompts
- Group chats, etiquette and privacy
- Working with Llama models directly
- Running a Llama model on your own computer
- System prompts and chat templates
- Parameters: temperature, top_p and max tokens
- Few-shot examples and structured JSON output
- Advanced prompting
- Prompting Llama for code
- Retrieval-augmented prompting: answering from your own documents
- Evaluating and comparing answers
- Safety, limits and a final project
- Safety, limits and responsible use
- Final project: build a study buddy assistant
Why settings matter
A language model does not pick one fixed answer. At each step it calculates how likely each possible next word piece is, then chooses one. The settings control how that choice is made. You usually cannot change them in Meta AI, but you can in tools you run yourself, and you can set them when you call a model from code.
Temperature
Temperature controls how adventurous the choice is.
- Low (close to 0): the model nearly always takes the most likely next piece. Answers are steady, predictable and repeatable.
- Higher (around 1): the model sometimes takes less likely pieces. Answers are more varied, more creative, and more likely to wander or make errors.
Think of a student answering an exam. At low temperature they write the safest standard answer. At high temperature they try more original ideas, and sometimes get them wrong.
| Task | Start with |
|---|---|
| Extracting data, JSON, classification | Low, close to 0 |
| Code, factual questions | Low to medium, 0.2 to 0.5 |
| Emails, summaries | Medium, about 0.5 to 0.7 |
| Brainstorming, stories, names | Higher, 0.8 to 1.0 |
These are starting points from my own use, not rules. Each tool has its own default, and good values depend on the model. Test with your task.
Top_p
Top_p, also called nucleus sampling, is another way to limit the choice. Instead of changing how bold the model is, it cuts off the unlikely options. With top_p at 0.9, the model chooses only among the most likely options that together make up 90 percent of the probability. Lower values mean a narrower, safer choice.
A common piece of advice, which I follow, is to change temperature or top_p, but not both at once. If you change two things you cannot tell which one did the work.
Max tokens
A token is a small piece of text, often part of a word. The maximum output setting limits how many tokens the model may write in one reply. If it is too low, the answer is cut off mid-sentence. If it is very high, it costs more time and, on paid services, more money. In Ollama this option is named num_predict, and other tools use names such as max_tokens. Check the name in your tool.
A rough rule for English is that a word is around one and a third tokens, but this varies by language and model. Urdu and other non-Latin scripts often use more tokens per word.
Setting them in Ollama
In a Modelfile:
FROM llama3.2
PARAMETER temperature 0.3
PARAMETER top_p 0.9
PARAMETER num_predict 300
This makes a calm model that writes at most 300 tokens.
An experiment you can run
Use this prompt three times at temperature 0.1, then three times at 1.0:
Give me one name for a coffee shop in Lahore. Reply with the name only.
At low temperature you will see the same or nearly the same name each time. At high temperature the names will differ more. Now try a factual question:
What is the capital of Australia? Reply with one word.
At low temperature the answer should be steady. At very high temperature, some models may get it wrong more often. This experiment shows what the setting does better than any explanation.
Other settings you will meet
- top_k: only consider the K most likely options.
- seed: a number that makes random choices repeatable in some tools.
- Context length: how much text the model can hold at once, including your prompt and its reply. Long chats can fall out of it.
- Repeat penalty: discourages repeating the same words.
Not every tool offers every setting, and names differ.
The common mistake
The common mistake is raising temperature to fix bad answers. Higher temperature does not make a model smarter. It makes it more random. If the answers are wrong, fix the prompt, add examples or use a larger model. Use temperature to tune style, not accuracy.
Try it yourself
Run the coffee shop experiment at three temperatures, three times each, and write all nine results in a small table. Then run a data task, such as "Reply with only the day of the week for 1 January 2000", at low and high temperature. Write one sentence on what you learned about each kind of task.
This course is free to read. Create a free account to enrol, save your progress and pick up where you left off.
Sign up free I already have an account