learning-it by example

#69 LLM engineering and evals 6.1 min

Detect LLM Hallucinations: 5 Checks Scored on 16 Answers

One check caught 1 of 8 made up answers. A strict model judge flagged 6 of 8 good ones.

1. What does a groundedness (faithfulness) check ask about a model's answer?
2. Sixteen answers were written about a shop handbook: eight that follow it and eight that do not. How did the strict model judge (llama3.2, asked whether every part of the claim is stated in the text) score?
3. In a test of a strict llama3.2 judge on 16 answers about a made-up shop handbook, the judge caught all 8 made-up answers. Why does that result tell you little?
4. The answer 'We do ship to Northern Ireland and to the Scottish islands' scored 0.86 on a cosine-similarity check with the all-minilm embedding model, in a test against a made-up shop handbook that says the opposite. Why was the score so high?
5. The figures check asks whether every figure in an answer appears in the handbook. Why did it miss an answer that gave helmets and accessories a 30 day return window?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Fool the figures check

    Copy the code folder first. The checks need Ollama with all-minilm running, because checks.py embeds the handbook when it is imported. In a Python prompt inside the folder run: import checks. Then call checks.figures_ok on 'Bikes can be returned within 90 days if unused.' and on 'Bikes can be returned within 14 days if unused.' Predict both results first. The 90 days answer should give False and the 14 days answer should give True, even though 14 days is the rule for helmets and not for bikes. Explain in one sentence why the check passes it.

    A hint

    Look at what figures_ok compares: the set of figures in the answer against the set of figures anywhere in handbook.md.

  2. Move the word overlap limit

    In the same Python prompt, run: from answers import ANSWERS. Then count how many of the made-up answers (the ones whose second value is False) have checks.overlap(answer) below 0.8, and how many of the good answers do. Compare with the video, which found 3 caught and 2 good ones flagged at 0.8. Now repeat with 0.6 and with 0.95. At 0.6 you should find 2 caught and none flagged, and at 0.95 you should find 3 caught and 4 flagged. Say which limit you would pick and why picking it from these same sixteen answers is a weakness.

    A hint

    Use a loop with an if on follows and on checks.overlap(answer) < limit. The video warns against picking a limit from the same answers you test on.

  3. Write an answer that slips through

    Write one new made-up answer about the handbook that you think figures_ok and overlap_ok will both pass, even though the handbook does not say it. Predict the results, then test it. For example, 'Points can be swapped for cash after 12 months.' gives True from figures_ok and an overlap of 1.00, although the handbook says points cannot be swapped for cash. Try two more of your own: one that changes a rule without changing any figures, and one that adds a new figure.

    A hint

    The overlap check counts only words longer than 3 letters. A sentence built from handbook words in a new order can still score 1.00.

  4. Predict the judge on your answers

    This task uses llama3.2 and takes a minute or two, so first write down a prediction. Pick three answers from your own tests above. Predict whether judge_ok (the strict prompt) and judge_loose_ok will return True for each. Then run them in Python with checks.judge_ok(answer) and checks.judge_loose_ok(answer) and compare. Keep a note of any answer where the strict judge said False for a good answer, as the video found for 6 of 8 good ones.

    A hint

    A reply only counts as a pass if it starts with YES. Temperature is 0, so rerunning the same answer should give the same reply.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Sixteen one-sentence answers that I wrote about one made-up handbook, one run, and one small local model (llama3.2) as the judge with two prompts; the 0.8 and 0.75 limits are my choice, and no claim splitting or larger judge was tested.

Up next in LLM engineering and evals

More in LLM engineering and evals

All LLM engineering and evals videos

Related videos