Hugging Face introduced LettucePrevent, a tool designed to reduce factual hallucinations in Retrieval-Augmented Generation (RAG) systems. The tool integrates a token-level detector directly into the generation loop using a custom LogitsProcessor. This approach outperforms existing hallucination detection models (HDMs) under streaming inference with lower latency. The regex-verifiable number detector achieves a >60% relative reduction in numeric hallucinations across all evaluated models, with minimal latency overhead. It is ready for immediate use with Hugging Face's generate() call.

LettucePrevent operates by modifying the autoregressive decoding loop. It inserts a step between token sampling: candidate extraction, hallucination scoring, logit penalization, and modified sampling. The system uses a skip_threshold parameter to bypass HDM evaluation when the top-candidate probability exceeds a threshold, preserving baseline throughput on high-confidence steps. The dominant cost lever is the runtime, as shown in the results. The tool's effectiveness depends on the model's tokenizer alignment with the Llama-3.1 boundaries it was trained on.

The tool was evaluated on the RAGTruth dataset, using 942 summary prompts for training and 450 for testing. LettucePrevent achieved a binary F1 score of 0.3886 for numeric hallucination detection, outperforming other detectors like lettucedetect-base-modernbert-en-v1 and tinylettuce-ettin-68m-en. The results show a significant reduction in hallucinations only when the model's tokenizer matches the Llama-3.1 boundaries. The tool's performance highlights the importance of tokenizer alignment for effective hallucination prevention.

Source: huggingface