Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 primarily 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. UForm-Gen-Chat is SFT version of [`UForm-Gen`](https://huggingface.co/unum-cloud/uform-gen) for multimodal chat.
|
20 |
+
|
21 |
+
### Usage
|
22 |
+
|
23 |
+
```bash
|
24 |
+
pip install uform
|
25 |
+
```
|
26 |
+
|
27 |
+
```python
|
28 |
+
from uform.gen_model import VLMForCausalLM, VLMProcessor
|
29 |
+
|
30 |
+
model = VLMForCausalLM.from_pretrained("unum-cloud/uform-gen-chat")
|
31 |
+
processor = VLMProcessor.from_pretrained("unum-cloud/uform-gen-chat")
|
32 |
+
|
33 |
+
messages = [
|
34 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
35 |
+
{"role": "user", "content": "<image> {Your message}"}
|
36 |
+
]
|
37 |
+
|
38 |
+
image = processor.image_processor(Image.open("zebra.jpg")).unsqueeze(0)
|
39 |
+
|
40 |
+
input_ids = processor.tokenizer.apply_chat_template(
|
41 |
+
messages, return_tensors="pt", add_generation_prompt=True
|
42 |
+
)
|
43 |
+
|
44 |
+
attention_mask = torch.ones(1, input_ids.shape[1] + processor.num_image_latents - 1)
|
45 |
+
|
46 |
+
inputs = {
|
47 |
+
"input_ids": input_ids,
|
48 |
+
"attention_mask": attention_mask,
|
49 |
+
"images": image,
|
50 |
+
}
|
51 |
+
|
52 |
+
outputs = model.generate(
|
53 |
+
**inputs,
|
54 |
+
do_sample=False,
|
55 |
+
use_cache=True,
|
56 |
+
max_new_tokens=1024,
|
57 |
+
eos_token_id=32001,
|
58 |
+
pad_token_id=processor.tokenizer.pad_token_id,
|
59 |
+
)
|
60 |
+
|
61 |
+
message = processor.batch_decode(outputs[:, inputs["input_ids"].shape[1]:-1])
|
62 |
+
|
63 |
+
```
|
64 |
+
|
65 |
+
|
66 |
+
## Evaluation
|
67 |
+
|
68 |
+
For captioning evaluation we measure CLIPScore and RefCLIPScore¹.
|
69 |
+
|
70 |
+
| Model | Size | Caption Length | CLIPScore | RefCLIPScore |
|
71 |
+
| :---------------------------------- | ---: | -------------: | --------: | -----------: |
|
72 |
+
| `llava-hf/llava-1.5-7b-hf` | 7B | Long | 0.878 | 0.529 |
|
73 |
+
| `llava-hf/llava-1.5-7b-hf` | 7B | Short | 0.886 | 0.531 |
|
74 |
+
| |
|
75 |
+
| `Salesforce/instructblip-vicuna-7b` | 7B | Long | 0.902 | 0.534 |
|
76 |
+
| `Salesforce/instructblip-vicuna-7b` | 7B | Short | 0.848 | 0.523 |
|
77 |
+
| |
|
78 |
+
| |
|
79 |
+
| `unum-cloud/uform-gen-chat` | 1.5B | Long | 0.860 | 0.525 |
|
80 |
+
| `unum-cloud/uform-gen-chat` | 1.5B | Short | 0.858 | 0.525 |
|
81 |
+
|
82 |
+
¹ We used `apple/DFN5B-CLIP-ViT-H-14-378` CLIP model.
|