skills/llm/multiple-choice-logits-processor/SKILL.md
Constrains LLM generation to a fixed set of valid choice tokens using a logits processor for structured single-token output.
npx skillsauth add wenmin-wu/ds-skills llm-multiple-choice-logits-processorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When an LLM must select from a discrete set of options (A/B/C/D, 1-9, yes/no), unconstrained generation can produce invalid answers, explanations, or refusals. A logits processor masks all tokens except the valid choices before sampling, guaranteeing a single valid token output. Works with vLLM, HuggingFace, and other frameworks.
import vllm
from logits_processor_zoo.vllm import MultipleChoiceLogitsProcessor
llm = vllm.LLM(model="Qwen/Qwen2.5-32B-AWQ", quantization="awq")
tokenizer = llm.get_tokenizer()
params = vllm.SamplingParams(
n=1, top_k=1, temperature=0, max_tokens=1,
skip_special_tokens=False,
logits_processors=[
MultipleChoiceLogitsProcessor(tokenizer, choices=["1","2","3","4","5"])
],
)
responses = llm.generate(prompts, params)
predictions = [r.outputs[0].text.strip() for r in responses]
MultipleChoiceLogitsProcessor with tokenizer and choiceslogits_processors in sampling paramsmax_tokens=1 — only one token neededoutlines, guidance) insteaddata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF