Video-Text-to-Text
Transformers
Safetensors
minicpmv
feature-extraction
MiniCPM-V
finetune
MLLM
custom_code
xjtupanda nielsr HF Staff commited on
Commit
cbb8742
·
verified ·
1 Parent(s): d68c078

Improve model card: Add comprehensive summary and usage example (#3)

Browse files

- Improve model card: Add comprehensive summary and usage example (e7b73dfda922493a1d4d0552884483fe713d6e19)


Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +77 -7
README.md CHANGED
@@ -14,21 +14,91 @@ tags:
14
  - MLLM
15
  ---
16
 
17
- <h1>Sparrow: Data-Efficient Video-LLM with Text-to-Image Augmentation</h1>
18
- <p>
19
- 💻 <a href="https://github.com/VITA-MLLM/Sparrow">GitHub</a>&nbsp&nbsp | &nbsp&nbsp 📑 <a href="https://arxiv.org/pdf/2411.19951">Paper</a> &nbsp&nbsp </a>
20
- </p>
21
 
22
  ## Model Summary
23
 
24
- * This is a part of the project [Sparrow](https://github.com/VITA-MLLM/Sparrow).
25
- * The video-LLM is fine-tuned from the image-LLM [MiniCPM-Llama3-V-2_5](https://huggingface.co/openbmb/MiniCPM-Llama3-V-2_5).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  ## License
28
 
29
  #### Model License
30
 
31
- * The code in this repo is released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.
32
  * The usage of MiniCPM-V series model weights must strictly follow [MiniCPM Model License.md](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md).
33
  * The models and weights of MiniCPM are completely free for academic research. After filling out a ["questionnaire"](https://modelbest.feishu.cn/share/base/form/shrcnpV5ZT9EJ6xYjh3Kx0J6v8g) for registration, are also available for free commercial use.
34
 
 
14
  - MLLM
15
  ---
16
 
17
+ # Sparrow: Data-Efficient Video-LLM with Text-to-Image Augmentation
18
+
19
+ 💻 [GitHub](https://github.com/VITA-MLLM/Sparrow) | 📑 [Paper](https://arxiv.org/pdf/2411.19951)
 
20
 
21
  ## Model Summary
22
 
23
+ This model, named Sparrow, was presented in the paper "Sparrow: Data-Efficient Video-LLM with Text-to-Image Augmentation". It builds upon the success of Multimodal Large Language Models (MLLMs) in vision understanding, specifically addressing the challenge of data efficiency in video-LLMs.
24
+
25
+ The paper revisits scaling with synthetic data and focuses on developing video-LLMs from a data-centric perspective. Preliminary experiments revealed a low learning efficiency when simply scaling up video data samples, which was attributed to a lack of instruction diversity.
26
+
27
+ **Key Highlights:**
28
+ - **Data Augmentation Method (Sparrow):** Proposes a novel data augmentation method that synthesizes video-like samples from pure text instruction data.
29
+ - **Efficient Training:** Mixing these synthetic samples with real video data enables a more efficient training scheme, achieving performance comparable to or even superior to baselines trained with significantly more samples.
30
+ - **Long Video Understanding:** Demonstrates that incorporating these synthetic samples can enhance the performance of long video understanding without requiring explicit training on long video data.
31
+
32
+ The video-LLM is fine-tuned from the image-LLM [MiniCPM-Llama3-V-2_5](https://huggingface.co/openbmb/MiniCPM-Llama3-V-2_5).
33
+
34
+ ## How to Use
35
+
36
+ You can use the Sparrow model with the `transformers` library. For more detailed instructions on video loading (e.g., extracting frames) and advanced usage scenarios, please refer to the project's [GitHub repository](https://github.com/VITA-MLLM/Sparrow).
37
+
38
+ First, ensure you have the necessary dependencies installed:
39
+
40
+ ```bash
41
+ pip install transformers torch accelerate
42
+ pip install -U flash-attn --no-build-isolation # For efficient training and inference
43
+ ```
44
+
45
+ Here's a quick example to get started with inference using an image as a proxy for video frames. In a full video-LLM setup, you would process a sequence of frames from a video.
46
+
47
+ ```python
48
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
49
+ import torch
50
+ from PIL import Image
51
+ import requests
52
+ from io import BytesIO
53
+
54
+ # The model is fine-tuned from openbmb/MiniCPM-Llama3-V-2_5
55
+ model_id = "openbmb/MiniCPM-Llama3-V-2_5"
56
+
57
+ # Load model, tokenizer, and processor
58
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
59
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="cuda", trust_remote_code=True)
60
+ processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
61
+
62
+ model.eval()
63
+
64
+ # --- Example: Using a single image as a proxy for a video frame ---
65
+ # For a real video-text-to-text task, you would typically:
66
+ # 1. Load a video using libraries like `decord` or `imageio`.
67
+ # 2. Extract a sequence of representative frames from the video.
68
+ # 3. Pass these frames as a list of PIL Images to the processor.
69
+
70
+ # For demonstration, we use a single dummy image:
71
+ image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg"
72
+ response = requests.get(image_url)
73
+ image_frame = Image.open(BytesIO(response.content)).convert("RGB")
74
+
75
+ # Prepare the conversation input with image and text
76
+ # For video input, 'content' would be a list like: [frame1, frame2, ..., question_text]
77
+ question = "Describe the scene shown in this image in detail."
78
+ messages = [{'role': 'user', 'content': [image_frame, question]}]
79
+
80
+ # Process inputs
81
+ inputs = processor(messages, return_tensors="pt")
82
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
83
+
84
+ # Generate text response
85
+ with torch.no_grad():
86
+ outputs = model.generate(
87
+ **inputs,
88
+ max_new_tokens=100,
89
+ do_sample=False,
90
+ repetition_penalty=1.05,
91
+ )
92
+
93
+ response_text = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
94
+ print(response_text)
95
+ ```
96
 
97
  ## License
98
 
99
  #### Model License
100
 
101
+ * The code in this repo is released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.
102
  * The usage of MiniCPM-V series model weights must strictly follow [MiniCPM Model License.md](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md).
103
  * The models and weights of MiniCPM are completely free for academic research. After filling out a ["questionnaire"](https://modelbest.feishu.cn/share/base/form/shrcnpV5ZT9EJ6xYjh3Kx0J6v8g) for registration, are also available for free commercial use.
104