Image-to-Text
Transformers
Safetensors
qwen2_5_vl
image-text-to-text
OCR
vision-language
VLM
Reasoning
document-to-markdown
qwen2.5
markdown
extraction
RAG
text-generation-inference
Instructions to use numind/NuMarkdown-8B-Thinking with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use numind/NuMarkdown-8B-Thinking with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="numind/NuMarkdown-8B-Thinking")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("numind/NuMarkdown-8B-Thinking") model = AutoModelForMultimodalLM.from_pretrained("numind/NuMarkdown-8B-Thinking", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -165,45 +165,6 @@ Pàgina 2 de 2
|
|
| 165 |
|
| 166 |
## Quick start: 🤗 Transformers
|
| 167 |
|
| 168 |
-
```python
|
| 169 |
-
from __future__ import annotations
|
| 170 |
-
|
| 171 |
-
import torch
|
| 172 |
-
from PIL import Image
|
| 173 |
-
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
|
| 174 |
-
|
| 175 |
-
model_id = "Numind/NuMarkdown-reasoning"
|
| 176 |
-
|
| 177 |
-
processor = AutoProcessor.from_pretrained(
|
| 178 |
-
model_id,
|
| 179 |
-
trust_remote_code=True,
|
| 180 |
-
)
|
| 181 |
-
|
| 182 |
-
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 183 |
-
model_id,
|
| 184 |
-
torch_dtype=torch.bfloat16,
|
| 185 |
-
attn_implementation="flash_attention_2",
|
| 186 |
-
device_map="auto",
|
| 187 |
-
trust_remote_code=True,
|
| 188 |
-
)
|
| 189 |
-
|
| 190 |
-
img = Image.open("invoice.png").convert("RGB")
|
| 191 |
-
messages = [{
|
| 192 |
-
"role": "user",
|
| 193 |
-
"content": [
|
| 194 |
-
{"type": "image"},
|
| 195 |
-
],
|
| 196 |
-
}]
|
| 197 |
-
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 198 |
-
enc = processor(text=prompt, images=[img], return_tensors="pt").to(model.device)
|
| 199 |
-
|
| 200 |
-
with torch.no_grad():
|
| 201 |
-
out = model.generate(**enc, max_new_tokens=5000)
|
| 202 |
-
|
| 203 |
-
print(processor.decode(out[0].split("<answer>")[1].split("</answer>")[0], skip_special_tokens=True))
|
| 204 |
-
```
|
| 205 |
-
|
| 206 |
-
|
| 207 |
## vLLM:
|
| 208 |
```
|
| 209 |
vllm serve numind/NuMarkdown-reasoning --trust_remote_code --limit-mm-per-prompt image=1
|
|
@@ -246,4 +207,42 @@ chat_response = client.chat.completions.create(
|
|
| 246 |
|
| 247 |
reasoning = chat_response.choices[0].message.content.split("<thining>")[1].split("</thining>")[0]
|
| 248 |
answer = chat_response.choices[0].message.content.split("<answer>")[1].split("</answer>")[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
```
|
|
|
|
| 165 |
|
| 166 |
## Quick start: 🤗 Transformers
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
## vLLM:
|
| 169 |
```
|
| 170 |
vllm serve numind/NuMarkdown-reasoning --trust_remote_code --limit-mm-per-prompt image=1
|
|
|
|
| 207 |
|
| 208 |
reasoning = chat_response.choices[0].message.content.split("<thining>")[1].split("</thining>")[0]
|
| 209 |
answer = chat_response.choices[0].message.content.split("<answer>")[1].split("</answer>")[0]
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
```python
|
| 213 |
+
from __future__ import annotations
|
| 214 |
+
|
| 215 |
+
import torch
|
| 216 |
+
from PIL import Image
|
| 217 |
+
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
|
| 218 |
+
|
| 219 |
+
model_id = "Numind/NuMarkdown-reasoning"
|
| 220 |
+
|
| 221 |
+
processor = AutoProcessor.from_pretrained(
|
| 222 |
+
model_id,
|
| 223 |
+
trust_remote_code=True,
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 227 |
+
model_id,
|
| 228 |
+
torch_dtype=torch.bfloat16,
|
| 229 |
+
attn_implementation="flash_attention_2",
|
| 230 |
+
device_map="auto",
|
| 231 |
+
trust_remote_code=True,
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
img = Image.open("invoice.png").convert("RGB")
|
| 235 |
+
messages = [{
|
| 236 |
+
"role": "user",
|
| 237 |
+
"content": [
|
| 238 |
+
{"type": "image"},
|
| 239 |
+
],
|
| 240 |
+
}]
|
| 241 |
+
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 242 |
+
enc = processor(text=prompt, images=[img], return_tensors="pt").to(model.device)
|
| 243 |
+
|
| 244 |
+
with torch.no_grad():
|
| 245 |
+
out = model.generate(**enc, max_new_tokens=5000)
|
| 246 |
+
|
| 247 |
+
print(processor.decode(out[0].split("<answer>")[1].split("</answer>")[0], skip_special_tokens=True))
|
| 248 |
```
|