https://github.com/cliangyu/cola
[NeurIPS2023] Official implementation of the paper "Large Language Models are Visual Reasoning Coordinators"
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.6%) to scientific vocabulary
Keywords from Contributors
Repository
[NeurIPS2023] Official implementation of the paper "Large Language Models are Visual Reasoning Coordinators"
Basic Info
- Host: GitHub
- Owner: cliangyu
- License: other
- Language: Jupyter Notebook
- Default Branch: main
- Homepage: https://arxiv.org/abs/2310.15166
- Size: 5.92 MB
Statistics
- Stars: 105
- Watchers: 3
- Forks: 7
- Open Issues: 1
- Releases: 0
Metadata Files
README.md
🥤 Cola [NeurIPS 2023] Large Language Models are Visual Reasoning Coordinators

TL;DR
We use a language model (LM) to aggregate the outputs of 2+ vision-language models (VLMs). Our model assemble approach is named Cola (COordinative LAnguage model or visual reasoning). Cola is most effective with the LM finetuned (termed as Cola-FT). Cola is also effective with zero-shot or few-shot in-context learning (termed as Cola-Zero). Beside the performance gain, Cola is also more robust to the VLMs' errors. We show that Cola can be applied to various VLMs (including large multimodal models like InstructBLIP) and 7 datasets (VQA v2, OK-VQA, A-OKVQA, e-SNLI-VE, VSR, CLEVR, GQA), and it consistently improves the performance.
🍱 Environment Setup
I highly recommend you to update NVIDIA drivers and CUDA to the latest version in case of weird bugs. See requirements.txt for the environment where the code is tested with.
shell
conda env create -f cola.yml
We use bf16 for inference and finetuning, which supports newer GPUs.
🥙 Prepare Datasets and Models
shell
mkdir datasets
mkdir predictions
mkdir pretrained_models
Below are the datasets we tested, you don't have to download all. I suggest starting with A-OKVQA.
- A-OKVQA: download from official page
- OK-VQA: download from official page
- VQAv2: download from official page
- CLEVR: download from Kaggle
- COCO & GQA: download by LAVIS script
- VSR: download from official page
- e-SNLI-VE & Flickr30k: download from official page
We convert all the datasets to the format of A-OKVQA dataset. See ./data_utils for conversion scripts.
shell
datasets
├── aokvqa
├── okvqa
├── coco
│ ├── train2017
│ ├── val2017
│ └── test2017
├── esnlive
│ └── flicr30k_images
├── vsr
│ └── trainval2017
├── vqav2
├── gqa
│ └── images
└── clevr
Download OFA model from Huggingface. Other models can be downloaded automatically.
shell
cd ..
git lfs clone https://huggingface.co/OFA-Sys/ofa-large
🚀 Inference
```shell
1. Get the plausible answers for the validation set
python query/queryblip.py --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task vqa --bs 128 --prediction-out ./predictions/aokvqablipvqaval-da.json
python query/queryofa.py --vlm-model-path ../OFA-large --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task vqa --bs 128 --prediction-out ./predictions/aokvqaofavqaval-da.json
2. Get the captions for the validation set
python query/queryblip.py --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task caption --bs 128 --prediction-out ./predictions/aokvqablipcaptionval-da.json
python query/queryofa.py --vlm-model-path ../OFA-large --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task caption --bs 128 --prediction-out ./predictions/aokvqaofacaptionval-da.json
3. Query the language model, Cola-Zero. Delete "--incontext --num-examples 2" for 0-shot inference.
python query/queryflan.py --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task vqa --bs 128 --prediction-out ./predictions/aokvqacola2-da.json --max-new-tokens 250 --llm google/flan-t5-small --vlm1 ofa --vlm2 blip --include-profile --include-caption --include-choices --incontext --num-examples 2
Another example: query Mistral-7B, with InstructBLIP-XL and XXL
python query/queryllm.py --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task vqa --bs 128 --prediction-out ./predictions/aokvqamistral_cola2-da.json --max-new-tokens 250 --llm mistralai/Mistral-7B-v0.1 --vlm1 insblipt5xl --vlm2 insblipt5xxl --include-profile --include-caption --include-choices --incontext --num-examples 2
Another example: query Mistral-7B, on test set of aokvqa
python query/queryllm.py --data-dir ./datasets/ --dataset-name aokvqa --split test --vlm-task vqa --bs 128 --prediction-out ./predictions/aokvqamistralcola2test-da.json --max-new-tokens 250 --llm mistralai/Mistral-7B-v0.1 --vlm1 insblipt5xl --vlm2 insblipt5xxl --include-profile --include-caption --include-choices --incontext --num-examples 2
Another example: query Vicuna-7B, on test set of aokvqa
python query/queryllm.py --data-dir ./datasets/ --dataset-name aokvqa --split test --vlm-task vqa --bs 16 --prediction-out ./predictions/aokvqavicunacola2test-da.json --max-new-tokens 250 --llm lmsys/vicuna-7b-v1.5-16k --vlm1 insblipt5xl --vlm2 insblipt5xxl --include-profile --include-caption --include-choices --incontext --num-examples 2
4. Evaluate the predictions (multiple choice), see "evaluate.sh" for direct answer evaluation.
export PYTHONPATH=. export DATADIR=./datasets/ export DATASET=aokvqa export SPLIT=val export LOGDIR=./logs/ export PREDSDIR=./predictions export PTMODELDIR=./pretrainedmodels/ export PREFIX=aokvqa_cola0
python evaluation/preparepredictions.py \ --data-dir ${DATADIR} --dataset ${DATASET} \ --split ${SPLIT} \ --da ${PREDSDIR}/${PREFIX}-da.json \ --mc ${PREDSDIR}/${PREFIX}-mc.json \ --out ${PREDS_DIR}/${PREFIX}.json
python evaluation/evalpredictions.py \ --data-dir ${DATADIR} --dataset ${DATASET} \ --split ${SPLIT} \ --preds ${PREDS_DIR}/${PREFIX}.json ```
🎛️ Finetuning
```shell
Get the plausible answers and captions for both training and validation sets (see Step 1 and 2 of Inference)
1. Finetune the language model, Cola-FT. Delete "--include-choices" for direct answer datasets. Need to "wandb login" before finetuning.
export MODELNAME=aokblipofaft WANDBRUNID=${MODELNAME} python query/finetuneflan.py \ --data-dir ./datasets/ --dataset-name aokvqa --split train --val-split val \ --bs 16 --llm google/flan-t5-xxl --vlm1 blip --vlm2 ofa \ --prediction-out placeholder --include-profile --include-caption --include-choices
Another example: finetune Mistral-7B or other decoder-only models
export MODELNAME=aokinsblipt5xlinsblipt5xxlmistralft WANDBRUNID=${MODELNAME} python query/finetune_llm.py --data-dir ./datasets/ --dataset-name aokvqa --split train --val-split val --bs 16 --llm mistralai/Mistral-7B-v0.1 --vlm1 insblipt5xl --vlm2 insblipt5xxl --prediction-out placeholder --include-profile --include-caption --include-choices
2. Query the finetuned model. We don't suggest using few-shot in-context learning for finetuned models.
python query/queryflan.py --data-dir ./datasets/ --dataset-name aokvqa --split val --vlm-task vqa --bs 128 --max-new-tokens 250 --prediction-out ./predictions/aokvqacolaft-da.json --max-new-tokens 250 --llm pretrainedmodels/${MODELNAME}/{theepochyou_test} --vlm1 blip --vlm2 ofa --include-choices --include-profile --include-caption
Another example: query vicuna model on the test set of aokvqa
python query/queryllm.py --data-dir ./datasets/ --dataset-name aokvqa --split test --vlm-task vqa --bs 16 --prediction-out ./predictions/aokvqavicunacolaft-da.json --max-new-tokens 250 --llm ./pretrainedmodels/aokinsblipt5xlinsblipt5xxlvicunaft/lmsys/vicuna-7b-v1.5-16klanguageprofilebs16epoch0 --vlm1 insblipt5xl --vlm2 insblipt5xxl --include-profile --include-caption --include-choices
3. Evaluate. The evaluation script is the same as Step 4 of Inference.
```
📚 Citation
If you use this code in your research, please kindly cite this work.
```bibtex @article{chen2023large, title={Large Language Models are Visual Reasoning Coordinators}, author={Chen, Liangyu and Li, Bo and Shen, Sheng and Yang, Jingkang and Li, Chunyuan and Keutzer, Kurt and Darrell, Trevor and Liu, Ziwei}, journal={Advances in Neural Information Processing Systems}, year={2023} }
@inproceedings{ chen2023language, title={Language Models are Visual Reasoning Coordinators}, author={Liangyu Chen and Bo Li and Sheng Shen and Jingkang Yang and Chunyuan Li and Kurt Keutzer and Trevor Darrell and Ziwei Liu}, booktitle={ICLR 2023 Workshop on Mathematical and Empirical Understanding of Foundation Models}, year={2023}, url={https://openreview.net/forum?id=kdHpWogtX6Y} } ```
🙏 Acknowledgements
Evaluation code is borrowed from aokvqa. Part of this README is borrowed from visualpromptretrieval.
Owner
- Name: Liangyu Chen
- Login: cliangyu
- Kind: user
- Location: Singapore
- Company: Nanyang Technological University
- Website: cliangyu.com
- Twitter: cliangyu_
- Repositories: 1
- Profile: https://github.com/cliangyu
GitHub Events
Total
- Watch event: 5
Last Year
- Watch event: 5
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| cliangyu | c****d@g****m | 8 |
| Guspan Tanadi | 3****i | 4 |
| Liangyu Chen | 4****h | 2 |
| Ziniu Zhang | m****u@g****m | 2 |
| Ikko Eltociear Ashimine | e****r@g****m | 1 |
| shulin16 | t****6@g****m | 1 |
Issues and Pull Requests
Last synced: about 1 year ago
All Time
- Total issues: 2
- Total pull requests: 2
- Average time to close issues: about 17 hours
- Average time to close pull requests: about 4 hours
- Total issue authors: 2
- Total pull request authors: 2
- Average comments per issue: 3.5
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- yeppp27 (1)
- ichimiya13 (1)
Pull Request Authors
- eltociear (1)
- guspan-tanadi (1)