---
title: You have a helper that returns token log-probabilities from an LLM for a batch of prompts. Build a binary classifier on…
url: https://gurkanozkan.ai/learn/questions/applied-llm-cod-04/
markdown: https://gurkanozkan.ai/learn/questions/applied-llm-cod-04.md
kind: question
role: Applied LLM
stage: Coding
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/applied-llm-cod-04.json
robots: noindex
---

# You have a helper that returns token log-probabilities from an LLM for a batch of prompts. Build a binary classifier on top of it: write the prompt, turn log-probs into a calibrated score rather than a hard label, then improve it.

Applied LLM · Coding · Medium

## Answer

*Model answer, written in a candidate's voice*

### In short

- Prompt asks for exactly one label token; verify tokenisation/casing and use few-shot examples only if they help.
- Score is softmax over the label tokens' first-token log-probs, renormalised, not argmax or raw log-prob.
- Choose threshold on a labelled validation set for the target precision/recall; check reliability curve and recalibrate if needed.
- Improve by trying label-token variants, prompt wording, few-shot examples, ensembling prompts/samples, and an abstain/other class for mass outside labels.
- Batch requests, retry/timeout, and treat missing or failed logprobs as unknown/abstain rather than silently negative.

### In full

I would make the prompt end with a strict instruction like “Answer with exactly one token: Yes or No,” then verify that “Yes” and “No” are single tokens in the model’s tokeniser (including leading spaces and casing), adding few-shot examples only if they improve validation behaviour. The classifier score is softmax over those label tokens’ first-token log-probabilities, renormalised so the two label probabilities sum to 1, rather than a raw log-prob or an argmax string; if the labels are not single tokens, I would use constrained decoding or sequence-level scoring instead of pretending they are. I would pick the decision threshold on a labelled validation set to hit the target precision/recall, then plot a reliability curve and apply temperature scaling or isotonic calibration if the probabilities are miscalibrated. To improve it, I would compare label-token choices (“Yes/No” vs “yes/no” vs “positive/negative”), prompt wording, few-shot examples, and averaged probabilities across multiple prompts or samples, while explicitly handling mass outside the label tokens with an abstain/other class or low-confidence rejection. In code I would batch prompts, set timeouts/retries, and mark missing logprobs or failed calls as unknown/abstain rather than silently treating them as negative, keeping the validation/test split clean so the threshold and calibration are not tuned on test data.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- Prompt constrains the answer to single label tokens (watch tokenisation: leading spaces, casing); few-shot if helpful
- Score = softmax over the label tokens' log-probs (renormalised), not a raw log-prob or an argmax string
- Threshold chosen on a labelled validation set for the target precision/recall; calibration check (reliability curve)
- Improvements: prompt refinement, label-token choice, ensembling multiple prompts/samples, handling mass outside label tokens
- Batching and error handling in the code

## Common mistakes

- Comparing un-normalised log-probs across labels
- ignoring probability mass on other tokens

## Topic guides

- [Prompting, few-shot and structured output](https://gurkanozkan.ai/learn/topics/prompting.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
