Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- vqa
|
| 7 |
+
- visual-question-answering
|
| 8 |
+
- knowledge-guided
|
| 9 |
+
- vit
|
| 10 |
+
- flan-t5
|
| 11 |
+
- ok-vqa
|
| 12 |
+
- multimodal
|
| 13 |
+
- pytorch
|
| 14 |
+
datasets:
|
| 15 |
+
- ok-vqa
|
| 16 |
+
pipeline_tag: visual-question-answering
|
| 17 |
+
library_name: pytorch
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Knowledge-Guided VQA Models
|
| 21 |
+
|
| 22 |
+
This repository contains trained model weights for **Knowledge-Guided Visual Question Answering** on the [OK-VQA](https://okvqa.allenai.org/) dataset.
|
| 23 |
+
|
| 24 |
+
These models explore different strategies for injecting external LLM-derived knowledge (visual focus cues and semantic knowledge) into a frozen Vision Transformer (ViT) + Flan-T5 pipeline for open-ended VQA.
|
| 25 |
+
|
| 26 |
+
## ποΈ Architecture
|
| 27 |
+
|
| 28 |
+
| Component | Model |
|
| 29 |
+
|:---|:---|
|
| 30 |
+
| Vision Encoder | `google/vit-base-patch16-224` |
|
| 31 |
+
| Text Encoder | CLIP Text (`openai/clip-vit-base-patch16`) |
|
| 32 |
+
| Decoder (Answer Generator) | `google/flan-t5-small` |
|
| 33 |
+
| Dataset | OK-VQA (train + val split) |
|
| 34 |
+
|
| 35 |
+
## π¦ Available Models
|
| 36 |
+
|
| 37 |
+
### 1. `best_baseline_model.pth` (309 MB)
|
| 38 |
+
- **Strategy:** No external knowledge. Standard ViT β CLS projection β T5 decoder.
|
| 39 |
+
- **Purpose:** Serves as the baseline for comparison.
|
| 40 |
+
|
| 41 |
+
### 2. `best_fusion_model.pth` (313 MB)
|
| 42 |
+
- **Strategy:** Late Fusion. Concatenates ViT CLS token with CLIP-encoded guidance vector, then projects to T5.
|
| 43 |
+
- **Knowledge Source:** LLM-generated visual focus + semantic knowledge via CLIP text encoder.
|
| 44 |
+
|
| 45 |
+
### 3. `best_attention_model.pth` (325 MB)
|
| 46 |
+
- **Strategy:** Attention Modification. Injects per-layer guidance projections into the top 6 ViT self-attention layers.
|
| 47 |
+
- **Knowledge Source:** LLM-generated visual focus + semantic knowledge via CLIP text encoder.
|
| 48 |
+
|
| 49 |
+
## π§ Usage
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
import torch
|
| 53 |
+
from transformers import ViTModel, AutoTokenizer, AutoModelForSeq2SeqLM
|
| 54 |
+
|
| 55 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 56 |
+
|
| 57 |
+
# Load base models
|
| 58 |
+
t5_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
|
| 59 |
+
t5 = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small").to(device)
|
| 60 |
+
vit = ViTModel.from_pretrained("google/vit-base-patch16-224").to(device)
|
| 61 |
+
|
| 62 |
+
# Define your model class (see notebook for full definitions)
|
| 63 |
+
# Then load weights:
|
| 64 |
+
model = YourModelClass().to(device)
|
| 65 |
+
model.load_state_dict(torch.load("best_baseline_model.pth", map_location=device))
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## π Training Details
|
| 69 |
+
|
| 70 |
+
- **Optimizer:** Adam (lr=3e-5)
|
| 71 |
+
- **Early Stopping:** Patience = 3-4 epochs
|
| 72 |
+
- **Max Epochs:** 15
|
| 73 |
+
- **Batch Size:** 8
|
| 74 |
+
- **Evaluation Metrics:** Exact Match, Edit Similarity, Token F1, BERTScore
|
| 75 |
+
|
| 76 |
+
## π Citation
|
| 77 |
+
|
| 78 |
+
If you use these models in your research, please cite:
|
| 79 |
+
|
| 80 |
+
```bibtex
|
| 81 |
+
@misc{knowledge-guided-vqa-2026,
|
| 82 |
+
title={Knowledge-Guided Visual Question Answering with Adaptive Vision-Language Integration},
|
| 83 |
+
author={Aneerban},
|
| 84 |
+
year={2026},
|
| 85 |
+
publisher={Hugging Face},
|
| 86 |
+
url={https://huggingface.co/rishii100/knowledge-guided-vqa-models}
|
| 87 |
+
}
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## π License
|
| 91 |
+
|
| 92 |
+
MIT License
|