Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
---
|
6 |
+
<h1 align="center">UForm</h1>
|
7 |
+
<h3 align="center">
|
8 |
+
Pocket-Sized Multimodal AI<br/>
|
9 |
+
For Content Understanding and Generation<br/>
|
10 |
+
</h3>
|
11 |
+
|
12 |
+
## Description
|
13 |
+
|
14 |
+
UForm-Gen is a small generative vision-language model primarly designed for Image Captioning and Visual Question Answering. The model consists of two parts:
|
15 |
+
|
16 |
+
1. [UForm Vision Encoder](https://huggingface.co/unum-cloud/uform-vl-english)
|
17 |
+
2. [Sheared-LLaMA-1.3B](https://huggingface.co/princeton-nlp/Sheared-LLaMA-1.3B) manually tuned on the instruction dataset
|
18 |
+
|
19 |
+
The model was pre-trained on: MSCOCO, SBU Captions, Visual Genome, VQAv2, GQA and a few internal datasets.
|
20 |
+
|
21 |
+
### Usage
|
22 |
+
|
23 |
+
```bash
|
24 |
+
pip install uform
|
25 |
+
```
|
26 |
+
|
27 |
+
The generative model can be used to caption images, summarize their content, or answer questions about them.
|
28 |
+
The exact behavior is controlled by prompts.
|
29 |
+
|
30 |
+
```python
|
31 |
+
from uform.gen_model import VLMForCausalLM, VLMProcessor
|
32 |
+
|
33 |
+
model = VLMForCausalLM.from_pretrained("unum-cloud/uform-gen")
|
34 |
+
processor = VLMProcessor.from_pretrained("unum-cloud/uform-gen")
|
35 |
+
|
36 |
+
# [cap] Narrate the contents of the image with precision.
|
37 |
+
# [cap] Summarize the visual content of the image.
|
38 |
+
# [vqa] What is the main subject of the image?
|
39 |
+
prompt = "[cap] Summarize the visual content of the image."
|
40 |
+
image = Image.open("zebra.jpg")
|
41 |
+
|
42 |
+
inputs = processor(texts=[prompt], images=[image], return_tensors="pt")
|
43 |
+
with torch.inference_mode():
|
44 |
+
output = model.generate(
|
45 |
+
**inputs,
|
46 |
+
do_sample=False,
|
47 |
+
use_cache=True,
|
48 |
+
max_new_tokens=128,
|
49 |
+
eos_token_id=32001,
|
50 |
+
pad_token_id=processor.tokenizer.pad_token_id
|
51 |
+
)
|
52 |
+
|
53 |
+
prompt_len = inputs["input_ids"].shape[1]
|
54 |
+
decoded_text = processor.batch_decode(output[:, prompt_len:])[0]
|
55 |
+
```
|
56 |
+
|
57 |
+
|
58 |
+
## Evaluation
|
59 |
+
|
60 |
+
For captioning evaluation we measure CLIPScore and RefCLIPScore¹.
|
61 |
+
|
62 |
+
| Model | Size | Caption Length | CLIPScore | RefCLIPScore |
|
63 |
+
| :---------------------------------- | ---: | -------------: | --------: | -----------: |
|
64 |
+
| `llava-hf/llava-1.5-7b-hf` | 7B | Long | 0.878 | 0.529 |
|
65 |
+
| `llava-hf/llava-1.5-7b-hf` | 7B | Short | 0.886 | 0.531 |
|
66 |
+
| |
|
67 |
+
| `Salesforce/instructblip-vicuna-7b` | 7B | Long | 0.902 | 0.534 |
|
68 |
+
| `Salesforce/instructblip-vicuna-7b` | 7B | Short | 0.848 | 0.523 |
|
69 |
+
| |
|
70 |
+
| `unum-cloud/uform-gen` | 1.5B | Long | 0.847 | 0.523 |
|
71 |
+
| `unum-cloud/uform-gen` | 1.5B | Short | 0.842 | 0.522 |
|
72 |
+
| |
|
73 |
+
| `unum-cloud/uform-gen-chat` | 1.5B | Long | 0.860 | 0.525 |
|
74 |
+
| `unum-cloud/uform-gen-chat` | 1.5B | Short | 0.858 | 0.525 |
|
75 |
+
|
76 |
+
Results for VQAv2 evaluation.
|
77 |
+
|
78 |
+
| Model | Size | Accuracy |
|
79 |
+
| :------------------------- | ---: | -------: |
|
80 |
+
| `llava-hf/llava-1.5-7b-hf` | 7B | 78.5 |
|
81 |
+
| `unum-cloud/uform-gen` | 1.5B | 66.5 |
|
82 |
+
|
83 |
+
¹ We used `apple/DFN5B-CLIP-ViT-H-14-378` CLIP model.
|
84 |
+
|
85 |
+
|
86 |
+
## Speed
|
87 |
+
|
88 |
+
On RTX 3090, the following performance is expected on text token generation using `float16`, equivalent PyTorch settings, and greedy decoding.
|
89 |
+
|
90 |
+
| Model | Size | Speed | Speedup |
|
91 |
+
| :---------------------------------- | ---: | ------------------: | --------: |
|
92 |
+
| `llava-hf/llava-1.5-7b-hf` | 7B | ~ 40 tokens/second | |
|
93 |
+
| `Salesforce/instructblip-vicuna-7b` | 7B | ~ 40 tokens/second | |
|
94 |
+
| `unum-cloud/uform-gen` | 1.5B | ~ 140 tokens/second | __x 3.5__ |
|
95 |
+
|