Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoProcessor
|
3 |
from PIL import Image
|
@@ -41,4 +91,9 @@ generated_ids = model.generate(**inputs, max_new_tokens=256, do_sample=True, tem
|
|
41 |
generated_ids_trimmed = [out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
|
42 |
output_text = processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
43 |
|
44 |
-
print(output_text)
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
library_name: transformers
|
4 |
+
tags:
|
5 |
+
- dots_ocr
|
6 |
+
- image-to-text
|
7 |
+
- ocr
|
8 |
+
- document-parse
|
9 |
+
- layout
|
10 |
+
- table
|
11 |
+
- formula
|
12 |
+
- quantized
|
13 |
+
- 4-bit
|
14 |
+
base_model: rednote-hilab/dots.ocr
|
15 |
+
---
|
16 |
+
|
17 |
+
<div align="center">
|
18 |
+
<img src="https://raw.githubusercontent.com/rednote-hilab/dots.ocr/master/assets/logo.png" width="300"/>
|
19 |
+
</div>
|
20 |
+
|
21 |
+
# dots.ocr-4bit: A 4-bit Quantized Version
|
22 |
+
|
23 |
+
This repository contains a 4-bit quantized version of the powerful `dots.ocr` model by the **Rednote HiLab**. The quantization was performed using `bitsandbytes` (NF4 precision), providing significant memory and speed improvements with minimal performance loss, making this state-of-the-art model accessible on consumer-grade GPUs.
|
24 |
+
|
25 |
+
This work is entirely a derivative of the original model. All credit for the model architecture, training, and groundbreaking research goes to the original authors. A huge thank you to them for open-sourcing their work.
|
26 |
+
|
27 |
+
* **Original Model:** [rednote-hilab/dots.ocr](https://huggingface.co/rednote-hilab/dots.ocr)
|
28 |
+
* **Original GitHub:** [https://github.com/rednote-hilab/dots.ocr](https://github.com/rednote-hilab/dots.ocr)
|
29 |
+
* **Live Demo (Original):** [https://dotsocr.xiaohongshu.com](https://dotsocr.xiaohongshu.com)
|
30 |
+
|
31 |
+
## Model Description (from original authors)
|
32 |
+
> **dots.ocr** is a powerful, multilingual document parser that unifies layout detection and content recognition within a single vision-language model while maintaining good reading order. Despite its compact 1.7B-parameter LLM foundation, it achieves state-of-the-art(SOTA) performance.
|
33 |
+
|
34 |
+
## How to Use This 4-bit Version
|
35 |
+
|
36 |
+
First, ensure you have the necessary dependencies installed. Because this model uses custom code, you **must** clone the original repository and install it.
|
37 |
+
|
38 |
+
```bash
|
39 |
+
# It's recommended to clone the original repo to get all utility scripts
|
40 |
+
git clone https://github.com/rednote-hilab/dots.ocr.git
|
41 |
+
cd dots.ocr
|
42 |
+
|
43 |
+
# Install the custom code and dependencies
|
44 |
+
pip install -e .
|
45 |
+
pip install torch transformers accelerate bitsandbytes peft sentencepiece
|
46 |
+
```
|
47 |
+
|
48 |
+
You can then use the 4-bit model with the following Python script. Note the inclusion of generation parameters (repetition_penalty, do_sample, etc.), which are recommended to prevent potential looping with the quantized model.
|
49 |
+
|
50 |
+
```python
|
51 |
import torch
|
52 |
from transformers import AutoModelForCausalLM, AutoProcessor
|
53 |
from PIL import Image
|
|
|
91 |
generated_ids_trimmed = [out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
|
92 |
output_text = processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
93 |
|
94 |
+
print(output_text)
|
95 |
+
```
|
96 |
+
|
97 |
+
## License
|
98 |
+
|
99 |
+
This model is released under the MIT License, same as the original model.
|