๐Ÿ”Ž VL-Uncertainty

March 18, 2025 ยท View on GitHub


๐Ÿ”Ž VL-Uncertainty

Ruiyang Zhang, Hu Zhang, Zhedong Zheng*

Website | Paper | Code

๐Ÿ”ฅ News

  • 2025.3.16: โœจ Welcome to check out our newest work: Uncertainty-o, unveiling uncertainty in Large Multimodal Models (LMMs) in a model-agnostic manner, supporting both Large Comprehension Models and Large Generation Models.
  • 2024.12.19: ๐Ÿฃ Source code of VL-Uncertainty is released!

โšก Overview

๐Ÿ› ๏ธ Install

  • Create conda environment.
conda create -n VL-Uncertainty python=3.11;

conda activate VL-Uncertainty;
  • Install denpendency.
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121;

pip install transformers datasets flash-attn accelerate timm numpy sentencepiece protobuf qwen_vl_utils;

(Tested on NVIDIA H100 PCIe-80G, NVIDIA A100-PCIE-40GB, and A6000-48G)

๐Ÿš€ Quick Start

  • Run our demo code.
python demo.py;
  • This should produce the results below. VL-Uncertainty can successfully estimate high uncertainty for wrong LVLM answer and thereby detect hallucination!
--------------------------------------------------
- Demo image: .asset/img/titanic.png
- Question: What is the name of this movie?
- GT answer: Titanic.
--------------------------------------------------
- LVLM answer: The movie in the image is "Coco."
- LVLM answer accuracy: Wrong
--------------------------------------------------
- Estimated uncertianty: 2.321928094887362
- Uncertianty threshold: 1.0
--------------------------------------------------
- Hallucination prediction: Is hallucination
- Hallucination detection: Success!
--------------------------------------------------

๐Ÿ“ˆ Run

  • For MM-Vet (Free-form benchmark)
bash run/run_MMVet.sh;
  • For LLaVABench (Free-form benchmark)
bash run/run_LLaVABench.sh;
  • For MMMU (Mutli-choice benchmark)
bash run/run_MMMU.sh;
  • For ScienceQA (Mutli-choice benchmark)
bash run/run_ScienceQA.sh;

๐Ÿ„ Examples

  • VL-Uncertainty successfully detects LVLM hallucination:

  • VL-Uncertainty can also assign low uncertainty for correct answer and identify it as non-hallucinatory:

  • VL-Uncertainty effectively generalizes to physical-world scenario. (The following picture is my laptop captured by iPhone)

โŒจ๏ธ Code Structure

  • Code strucuture of this repostory is as follow:
โ”œโ”€โ”€ VL-Uncertainty/ 
โ”‚   โ”œโ”€โ”€ .asset/
โ”‚   โ”‚   โ”œโ”€โ”€ img/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ logo.png
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ titanic.png         # For demo
โ”‚   โ”œโ”€โ”€ benchmark/
โ”‚   โ”‚   โ”œโ”€โ”€ LLaVABench.py           # Free-form benchmark
โ”‚   โ”‚   โ”œโ”€โ”€ MMMU.py                 # Multi-choice benchmark
โ”‚   โ”‚   โ”œโ”€โ”€ MMVet.py                # Free-form benchmark
โ”‚   โ”‚   โ”œโ”€โ”€ ScienceQA.py            # Multi-choice benchmark
โ”‚   โ”œโ”€โ”€ llm/
โ”‚   โ”‚   โ”œโ”€โ”€ Qwen.py                 # LLM class
โ”‚   โ”œโ”€โ”€ lvlm/
โ”‚   โ”‚   โ”œโ”€โ”€ InternVL.py             # Support 26B, 8B, and 1B
โ”‚   โ”‚   โ”œโ”€โ”€ LLaVA.py                # Support 13B, 7B
โ”‚   โ”‚   โ”œโ”€โ”€ LLaVANeXT.py            # Support 13B, 7B
โ”‚   โ”‚   โ”œโ”€โ”€ Qwen2VL.py              # Support 72B, 7B, 2B
โ”‚   โ”œโ”€โ”€ run/
โ”‚   โ”‚   โ”œโ”€โ”€ run_LLaVABench.sh       # Benchmark VL-Uncertainty on LLaVABench
โ”‚   โ”‚   โ”œโ”€โ”€ run_MMMU.sh             # Benchmark VL-Uncertainty on MMMU
โ”‚   โ”‚   โ”œโ”€โ”€ run_MMVet.sh            # Benchmark VL-Uncertainty on MMVet
โ”‚   โ”‚   โ”œโ”€โ”€ run_ScienceQA.sh        # Benchmark VL-Uncertainty on ScienceQA
โ”‚   โ”œโ”€โ”€ util/
โ”‚   โ”‚   โ”œโ”€โ”€ misc.py                 # Helper function
โ”‚   โ”‚   โ”œโ”€โ”€ textual_perturbation.py # Various textural perturbation
โ”‚   โ”‚   โ”œโ”€โ”€ visual_perturbation.py  # Various visual perturbation
โ”‚   โ”œโ”€โ”€ .gitignore
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ VL-Uncertainty.py           # Include semantic-equvialent perturbation, uncertainty estimation, and hallucination detection
โ”‚   โ”œโ”€โ”€ demo.py                     # Quick start demo

โœจ Acknowledgement

๐Ÿ“Ž Citation

If you find our work useful for your research and application, please cite using this BibTeX:

@article{zhang2024vl,
  title={VL-Uncertainty: Detecting Hallucination in Large Vision-Language Model via Uncertainty Estimation},
  author={Zhang, Ruiyang and Zhang, Hu and Zheng, Zhedong},
  journal={arXiv preprint arXiv:2411.11919},
  year={2024}
}