Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shallow Focus, Deep Fixes: Enhancing Shallow Layers Vision Attention Sinks to Alleviate Hallucination in LVLMs (EMNLP'25 Oral)

License: MIT Arxiv

This repository provides the official PyTorch implementation of the following paper:

Shallow Focus, Deep Fixes: Enhancing Shallow Layers Vision Attention Sinks to Alleviate Hallucination in LVLMs

Overview

teaser

Hallucination, posed as a pervasive challenge of multi-modal large language models (MLLMs), has significantly impeded their real-world usage that demands precise judgment. Existing methods mitigate this issue with either training with specific designed data or inferencing with external knowledge from other sources, incurring inevitable additional costs. In this paper, we present OPERA, a novel MLLM decoding method grounded in an Over-trust Penalty and a Retrospection-Allocation strategy, serving as a nearly free lunch to alleviate the hallucination issue without additional data, knowledge, or training. Our approach begins with an interesting observation that, most hallucinations are closely tied to the knowledge aggregation patterns manifested in the self-attention matrix, i.e., MLLMs tend to generate new tokens by focusing on a few summary tokens, but not all the previous tokens. Such partial over-trust inclination results in the neglecting of image tokens and describes the image content with hallucination. Statistically, we observe an 80%∼95% co-currency rate between hallucination contents and such knowledge aggregation patterns. Based on the observation, OPERA introduces a penalty term on the model logits during the beam-search decoding to mitigate the over-trust issue, along with a rollback strategy that retrospects the presence of summary tokens in the previously generated tokens, and re-allocate the token selection if necessary. With extensive experiments, OPERA shows significant hallucination-mitigating performance on different MLLMs and metrics, proving its effec-tiveness and generality.

Setup

The main implementation of EAH is in transformers-4.29.2/src/transformers/models/llama/modeling_llama.

So it is convenient to use EAH decoding by just changing original modeling_llama to our modeling_llama_eah.

conda env create -f environment.yml
conda activate eah
python -m pip install -e transformers-4.29.2

Note: to implement EAH on other version of transformers, you can follow the steps as the follows:

  • Find the filefolder transformers-4.29.2/src/transformers/models/llama/.
  • Overwrite original modeling_llama to our modeling_llama_eah (with file name modeling_llama).

Evaluation

The following evaluation requires for MSCOCO 2014 dataset. Please download here and extract it in your data path.

Besides, it needs you to prepare the following checkpoints of 7B base models:

Arguments

Argument Example Description
--model llava-1.5 Specify the MLLM model, this codebase supports instructblip, minigpt4, llava-1.5, shikra.
--data-path /path/to/dataset Path to the dataset file or folder, e.g., COCO_2014/val2014/.
--pope-type random Type for POPE evaluation, supports random, popular, adversarial.
--LAYER_NUM 1 Specifies which Transformer layer’s attention will be processed.. Default: 1.
--HEAD_NUM k Specifies which attention head / head index is targeted for inspection or broadcasting. Default: k.
--THRES 0.002 Sets the attention strength threshold used to identify significant image-token attention.

POPE

python pope_eval.py --model MODEL_NAME --data_path /path/to/COCO --pope-type random --gpu-id GPU_IDs 

CHAIR

  • Generate the MLLM's responses and save them in a jsonl file:
python chair_eval.py --model MODEL_NAME --data_path /path/to/COCO --gpu-id GPU_IDs --beam 5 

Note: Please check out our released results in log/chair_eval_results for reproduction.

  • Calculate CHAIR using the generated jsonl file:
python chair.py --cap_file /path/to/jsonl --image_id_key image_id --caption_key caption --coco_path /path/to/COCO/annotations_trainval2014/annotations/ --save_path /path/to/save/jsonl

GPT-4V

The GPT-4V evaluation requires you to specify your API key in Line 88 of gpt4v_eval.py.

python gpt4v_eval.py --model MODEL_NAME --data_path /path/to/COCO --gpu-id GPU_IDs 

Acknowledgement

This repo is based on the MLLM codebase of OPERA, LAVIS and MiniGPT-4 and the CHAIR code of Maxlinn. Thanks for their impressive works!

Citation

@article{seeing,
  title={Seeing clearly by layer two: Enhancing attention heads to alleviate hallucination in lvlms},
  author={Zhang, Xiaofeng and Quan, Yihao and Gu, Chaochen and Shen, Chen and Yuan, Xiaosong and Yan, Shaotian and Cheng, Hao and Wu, Kaijie and Ye, Jieping},
  journal={The 2025 Conference on Empirical Methods in Natural Language Processing},
  year={2024}
}


@inproceedings{shallow,
  title={Shallow Focus, Deep Fixes: Enhancing Shallow Layers Vision Attention Sinks to Alleviate Hallucination in LVLMs},
  author={Zhang, Xiaofeng and Quan, Yihao and Shen, Chen and Gu, Chaochen and Yuan, Xiaosong and Yan, Shaotian and Cao, Jiawei and Cheng, Hao and Wu, Kaijie and Ye, Jieping},
  booktitle={The 2025 Conference on Empirical Methods in Natural Language Processing},
  year={2025}
}

About

[EMNLP 2025 Oral] 🎉 Shallow Focus, Deep Fixes: Enhancing Shallow Layers Vision Attention Sinks to Alleviate Hallucination in LVLMs

Resources

Stars

15 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages