Update README.md
Browse files
README.md
CHANGED
|
@@ -6,4 +6,133 @@ base_model:
|
|
| 6 |
- Qwen/Qwen2-VL-2B-Instruct
|
| 7 |
pipeline_tag: image-text-to-text
|
| 8 |
library_name: transformers
|
| 9 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- Qwen/Qwen2-VL-2B-Instruct
|
| 7 |
pipeline_tag: image-text-to-text
|
| 8 |
library_name: transformers
|
| 9 |
+
---
|
| 10 |
+
# Qwen2-VL-Math-Prase-2B-Instruct [ Math EQU]
|
| 11 |
+
|
| 12 |
+

|
| 13 |
+
|
| 14 |
+
The **Qwen2-VL-Math-Prase-2B-Instruct** model is a fine-tuned version of **Qwen/Qwen2-VL-2B-Instruct**, tailored for tasks that involve **Optical Character Recognition (OCR)**, **image-to-text conversion**, and **math problem solving with LaTeX formatting**. This model integrates a conversational approach with visual and textual understanding to handle multi-modal tasks effectively.
|
| 15 |
+
|
| 16 |
+
#### Key Enhancements:
|
| 17 |
+
|
| 18 |
+
* **SoTA understanding of images of various resolution & ratio**: Qwen2-VL achieves state-of-the-art performance on visual understanding benchmarks, including MathVista, DocVQA, RealWorldQA, MTVQA, etc.
|
| 19 |
+
|
| 20 |
+
* **Understanding videos of 20min+**: Qwen2-VL can understand videos over 20 minutes for high-quality video-based question answering, dialog, content creation, etc.
|
| 21 |
+
|
| 22 |
+
* **Agent that can operate your mobiles, robots, etc.**: with the abilities of complex reasoning and decision making, Qwen2-VL can be integrated with devices like mobile phones, robots, etc., for automatic operation based on visual environment and text instructions.
|
| 23 |
+
|
| 24 |
+
* **Multilingual Support**: to serve global users, besides English and Chinese, Qwen2-VL now supports the understanding of texts in different languages inside images, including most European languages, Japanese, Korean, Arabic, Vietnamese, etc.
|
| 25 |
+
|
| 26 |
+
| **File Name** | **Size** | **Description** | **Upload Status** |
|
| 27 |
+
|---------------------------|------------|------------------------------------------------|-------------------|
|
| 28 |
+
| `.gitattributes` | 1.52 kB | Configures LFS tracking for specific model files. | Initial commit |
|
| 29 |
+
| `README.md` | 203 Bytes | Minimal details about the uploaded model. | Updated |
|
| 30 |
+
| `added_tokens.json` | 408 Bytes | Additional tokens used by the model tokenizer. | Uploaded |
|
| 31 |
+
| `chat_template.json` | 1.05 kB | Template for chat-based model input/output. | Uploaded |
|
| 32 |
+
| `config.json` | 1.24 kB | Model configuration metadata. | Uploaded |
|
| 33 |
+
| `generation_config.json` | 252 Bytes | Configuration for text generation settings. | Uploaded |
|
| 34 |
+
| `merges.txt` | 1.82 MB | BPE merge rules for tokenization. | Uploaded |
|
| 35 |
+
| `model.safetensors` | 4.42 GB | Serialized model weights in a secure format. | Uploaded (LFS) |
|
| 36 |
+
| `preprocessor_config.json`| 596 Bytes | Preprocessing configuration for input data. | Uploaded |
|
| 37 |
+
| `vocab.json` | 2.78 MB | Vocabulary file for tokenization. | Uploaded |
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
### How to Use
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
|
| 44 |
+
from qwen_vl_utils import process_vision_info
|
| 45 |
+
|
| 46 |
+
# default: Load the model on the available device(s)
|
| 47 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 48 |
+
"prithivMLmods/Qwen2-VL-Math-Prase-2B-Instruct", torch_dtype="auto", device_map="auto"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
|
| 52 |
+
# model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 53 |
+
# "prithivMLmods/Qwen2-VL-Math-Prase-2B-Instruct",
|
| 54 |
+
# torch_dtype=torch.bfloat16,
|
| 55 |
+
# attn_implementation="flash_attention_2",
|
| 56 |
+
# device_map="auto",
|
| 57 |
+
# )
|
| 58 |
+
|
| 59 |
+
# default processer
|
| 60 |
+
processor = AutoProcessor.from_pretrained("prithivMLmods/Qwen2-VL-OCR-2B-Instruct")
|
| 61 |
+
|
| 62 |
+
# The default range for the number of visual tokens per image in the model is 4-16384. You can set min_pixels and max_pixels according to your needs, such as a token count range of 256-1280, to balance speed and memory usage.
|
| 63 |
+
# min_pixels = 256*28*28
|
| 64 |
+
# max_pixels = 1280*28*28
|
| 65 |
+
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
|
| 66 |
+
|
| 67 |
+
messages = [
|
| 68 |
+
{
|
| 69 |
+
"role": "user",
|
| 70 |
+
"content": [
|
| 71 |
+
{
|
| 72 |
+
"type": "image",
|
| 73 |
+
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
|
| 74 |
+
},
|
| 75 |
+
{"type": "text", "text": "Describe this image."},
|
| 76 |
+
],
|
| 77 |
+
}
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
# Preparation for inference
|
| 81 |
+
text = processor.apply_chat_template(
|
| 82 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 83 |
+
)
|
| 84 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 85 |
+
inputs = processor(
|
| 86 |
+
text=[text],
|
| 87 |
+
images=image_inputs,
|
| 88 |
+
videos=video_inputs,
|
| 89 |
+
padding=True,
|
| 90 |
+
return_tensors="pt",
|
| 91 |
+
)
|
| 92 |
+
inputs = inputs.to("cuda")
|
| 93 |
+
|
| 94 |
+
# Inference: Generation of the output
|
| 95 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 96 |
+
generated_ids_trimmed = [
|
| 97 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 98 |
+
]
|
| 99 |
+
output_text = processor.batch_decode(
|
| 100 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 101 |
+
)
|
| 102 |
+
print(output_text)
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
### **Key Features**
|
| 106 |
+
|
| 107 |
+
1. **Vision-Language Integration:**
|
| 108 |
+
- Combines **image understanding** with **natural language processing** to convert images into text.
|
| 109 |
+
|
| 110 |
+
2. **Optical Character Recognition (OCR):**
|
| 111 |
+
- Extracts and processes textual information from images with high accuracy.
|
| 112 |
+
|
| 113 |
+
3. **Math and LaTeX Support:**
|
| 114 |
+
- Solves math problems and outputs equations in **LaTeX format**.
|
| 115 |
+
|
| 116 |
+
4. **Conversational Capabilities:**
|
| 117 |
+
- Designed to handle **multi-turn interactions**, providing context-aware responses.
|
| 118 |
+
|
| 119 |
+
5. **Image-Text-to-Text Generation:**
|
| 120 |
+
- Inputs can include **images, text, or a combination**, and the model generates descriptive or problem-solving text.
|
| 121 |
+
|
| 122 |
+
6. **Secure Weight Format:**
|
| 123 |
+
- Uses **Safetensors** for faster and more secure model weight loading.
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
+
|
| 127 |
+
### **Training Details**
|
| 128 |
+
|
| 129 |
+
- **Base Model:** [Qwen/Qwen2-VL-2B-Instruct](#)
|
| 130 |
+
- **Model Size:**
|
| 131 |
+
- 2.21 Billion parameters
|
| 132 |
+
- Optimized for **BF16** tensor type, enabling efficient inference.
|
| 133 |
+
|
| 134 |
+
- **Specializations:**
|
| 135 |
+
- OCR tasks in images containing text.
|
| 136 |
+
- Mathematical reasoning and LaTeX output for equations.
|
| 137 |
+
|
| 138 |
+
---
|