Tokens, Temperature & Hallucination Questions with Answers

24 practice questions on Tokens, Temperature & Hallucination (AI Tools for Developers) with answers and step-by-step solutions. Try 10 samples below, then practise all 24 free in the AptiNest app.

Sample questions

Question 1Easy

Setting temperature to a low value is typically used when you want:

  1. Longer context windows
  2. Wild creative brainstorming
  3. Consistent, focused answers
  4. Answers in a random language

Answer: C. Consistent, focused answers

Explanation

Low temperature favours the most likely tokens, giving steadier output.

Step-by-step solution

  1. Temperature controls how random the output is.
  2. A low temperature favours the most likely tokens.
  3. This gives consistent, focused answers. The correct answer is C (Consistent, focused answers).

Why the other options are wrong

  • A. The context window is a separate setting from temperature.
  • B. Wild brainstorming needs a higher temperature, not a low one.
  • D. A low temperature does not make the language random.

Tip: Use a low temperature for facts and code, and a higher one for creative ideas.

Question 2Easy

Which statement about AI hallucinations is TRUE?

  1. They only happen with very short prompts
  2. They only happen in non-English languages
  3. They can happen even with good prompts, so checking output still matters
  4. They never happen in code

Answer: C. They can happen even with good prompts, so checking output still matters

Explanation

Better prompting and context reduce hallucinations but do not eliminate them.

Step-by-step solution

  1. A hallucination is a confident answer that is false or made up.
  2. Good prompts and context reduce hallucinations but do not remove them.
  3. So the output must still be checked. The correct answer is C.

Why the other options are wrong

  • A. Short prompts can still produce hallucinations.
  • B. Hallucinations happen in English too.
  • D. Code can be hallucinated too, for example a function or API that does not exist.

Tip: Check AI output against the docs or tests before you trust it.

Question 3Easy

A higher temperature setting generally makes a model's output:

  1. Shorter in every case
  2. More varied and less predictable
  3. Always more accurate and better grounded
  4. Exactly the same every time

Answer: B. More varied and less predictable

Explanation

Temperature controls randomness in token selection; higher values increase diversity, not correctness.

Step-by-step solution

  1. Higher temperature increases randomness in token selection.
  2. More randomness leads to more varied and less predictable outputs.
  3. This makes the model's output more diverse but less consistent.
  4. Therefore, higher temperature results in more varied and less predictable outcomes.
  5. The final answer is B (More varied and less predictable).

Why the other options are wrong

  • A. Higher temperature does not make output shorter in every case; it adds randomness to word choice.
  • C. Higher temperature does not improve accuracy; more randomness can make answers less grounded.
  • D. Exactly the same output every time is what low temperature aims for, not high temperature.

Tip: Higher temperature = more creativity, lower temperature = more consistency.

Question 4Easy

Which is a sign that an AI answer might be hallucinated?

  1. It compiles and passes the unit tests you wrote yourself
  2. It uses standard library functions you know
  3. It matches the official docs
  4. It cites a function or source you cannot find anywhere

Answer: D. It cites a function or source you cannot find anywhere

Explanation

If a referenced API or source can't be found, it may have been invented.

Step-by-step solution

  1. An AI hallucination creates fake sources or functions.
  2. If a source is not real, the answer is unreliable.
  3. Citing non-existent sources shows lack of accuracy.
  4. This indicates the answer may be made up.
  5. The correct sign is when a source cannot be found anywhere.

Why the other options are wrong

  • A. Passing your own unit tests does not prove an answer is not hallucinated; that check is limited.
  • B. Using standard library functions you know is normal and does not mean the answer is invented.
  • C. Matching official docs is a sign of accuracy, not hallucination, so it is not the warning sign.

Tip: Check if cited sources exist to spot AI hallucination.

Question 5Medium

Which setting is usually more suitable for generating code that must follow a strict format?

  1. Temperature has no relation to output
  2. A lower temperature
  3. A random temperature each time
  4. The highest available temperature

Answer: B. A lower temperature

Explanation

Lower temperature makes output more focused and consistent, which helps with deterministic, structured tasks.

Step-by-step solution

  1. Strict-format code needs output that is consistent and predictable.
  2. Temperature controls randomness: higher values vary more, lower values favour the most likely tokens.
  3. A lower temperature gives steadier, focused output that follows a fixed format. The correct answer is B (A lower temperature).

Why the other options are wrong

  • A. Temperature does affect output, because it controls how random the sampling is.
  • C. A random temperature each time gives unpredictable formats.
  • D. The highest temperature gives the most varied output, the opposite of what a strict format needs.

Tip: Use a low temperature for code, JSON and other strict formats; use higher values for brainstorming.

Question 6Medium

Which approach reduces hallucinated answers about your project's code?

  1. Raise the temperature so it considers more possibilities
  2. Ask the question in fewer words
  3. Give the relevant code as context and ask the model to cite file and line
  4. Use a longer conversation history about unrelated topics

Answer: C. Give the relevant code as context and ask the model to cite file and line

Explanation

Grounding answers in supplied context and asking for references makes claims checkable.

Step-by-step solution

  1. Giving the real code as context grounds the answer.
  2. Citing file and line makes checking easy.

Why the other options are wrong

  • A. Higher temperature adds randomness.
  • B. Fewer words give less context.
  • D. Unrelated history adds noise.

Tip: Give context, ask for citations.

Question 7Medium

Pasting a very long file and asking a question about one detail near the middle sometimes fails. A practical fix is to:

  1. Paste the file in a smaller font
  2. Ask the question before pasting anything at all
  3. Point to or paste the relevant section directly
  4. Remove all the whitespace from the file

Answer: C. Point to or paste the relevant section directly

Explanation

Focused context makes the relevant detail prominent instead of buried in a long input.

Step-by-step solution

  1. Pasting a long file hides key details in noise.
  2. Focusing on one part avoids confusion.
  3. Pointing to or pasting the section highlights it.
  4. This makes the answer clear and direct.
  5. Final answer: Point to or paste the relevant section directly.

Why the other options are wrong

  • A. A smaller font changes only how the text looks and does not help the model find the detail.
  • B. Asking before pasting gives the model no context for the question, so it cannot answer.
  • D. Removing whitespace does not fix the issue and can make the code harder to read.

Tip: Highlight key info before asking questions.

Question 8Medium

Why do some languages (e.g. Hindi in Devanagari) often use more tokens than English for similar text?

  1. Tokenisers are often trained mostly on English, so other scripts split into more pieces
  2. Models refuse to read Hindi
  3. Tokens are counted by number of characters only
  4. Hindi words are always longer than English words

Answer: A. Tokenisers are often trained mostly on English, so other scripts split into more pieces

Explanation

Tokeniser vocabularies favour common training text; less-represented scripts are split into more, smaller tokens.

Step-by-step solution

  1. A tokeniser builds its vocabulary from its training text.
  2. Most of that text is English, so common English words get whole tokens.
  3. Devanagari text is often split into smaller pieces, so it needs more tokens. The correct answer is A.

Why the other options are wrong

  • B. Models do read Hindi; the token count depends on how the text is split.
  • C. Tokens are not counted by characters alone; they depend on the tokeniser's vocabulary.
  • D. Hindi words are not always longer; the cause is the tokeniser's vocabulary.

Tip: Languages with less training data often cost more tokens for the same meaning.

Question 9Hard

A model says: "The requests library's get() has a retry=3 parameter." How should you treat this?

  1. Verify it in the docs; plausible-sounding parameters are often invented
  2. Ignore all library documentation from now on
  3. Accept it if the answer used code formatting
  4. Accept it because requests is a popular library the model must know well

Answer: A. Verify it in the docs; plausible-sounding parameters are often invented

Explanation

Popular libraries are still subject to invented parameters; in fact requests.get has no retry argument (retries are set via adapters).

Step-by-step solution

  1. Models can invent plausible parameters.
  2. Always check the official docs.

Why the other options are wrong

  • B. Docs are the check.
  • C. Formatting proves nothing.
  • D. Popularity does not prevent hallucination.

Tip: Docs are the truth.

Question 10Hard

You need the exact number of lines in a 5,000-line file. What is the most reliable way to use AI?

  1. Ask it to read the file and count in its head
  2. Have it write or run a command like wc -l rather than estimate
  3. Raise the temperature so it counts more carefully
  4. Ask it twice and average the answers

Answer: B. Have it write or run a command like wc -l rather than estimate

Explanation

Deterministic tools give exact answers; models estimating from text can miscount.

Step-by-step solution

  1. Wc -l is a command that counts lines exactly in Linux.
  2. AI should run this command rather than guess the count.
  3. This method ensures accuracy without estimation errors.
  4. Running wc -l directly gives the exact line number needed.
  5. The correct answer is to have AI run wc -l as it provides precise results.

Why the other options are wrong

  • A. Counting in its head is an estimate and can be wrong for a long file, so it is not reliable.
  • C. Higher temperature adds randomness and does not improve counting accuracy at all.
  • D. Averaging two guesses still gives an estimate that can be wrong, so it is not reliable.

Tip: For exact file line counts, use wc -l instead of relying on AI estimation.

Practise all 24 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all AI Tools for Developers topics · All topics