Views
No views yet
| Component | Spec |
|---|---|
| Type | Vision-Language Model (VLM) |
| Parameters | ~1B |
| Vision Encoder | 27-layer ViT, 1152 dim, 16 heads |
| Language Model | 24-layer decoder, 1024 dim, GQA (16Q/8KV) |
| Features | xdrope RoPE, QK normalization, RMS norm, SiLU SwiGLU |
| Dtype | float16 |
| Format | MLX |
1pip install mlx transformers torch torchvision Pillow
2git clone https://huggingface.co/AnandSingh/hunyuanocr-mlx1import mlx.core as mx
2from PIL import Image
3
4# Import the model code
5from hunyuan_ocr_mlx import HunyuanOCR, HunyuanOCRProcessor
6
7model = HunyuanOCR("config.json")
8model.load_weights("model.safetensors")
9processor = HunyuanOCRProcessor.from_pretrained(".")
10
11# Run OCR
12img = Image.open("document.jpg")
13prompt = "检测并识别图片中的文字,将文本坐标格式化输出。"
14processed = processor.process([img], [prompt])
15
16hidden_states, past_kvs = model(
17 input_ids=processed.input_ids,
18 pixel_values=processed.pixel_values,
19 position_ids=processed.position_ids,
20 attention_mask=processed.attention_mask,
21 grid_thw=processed.grid_thw,
22)
23
24# Generate
25logits = model.lm_head(hidden_states[:, -1:, :])
26next_token = mx.argmax(logits[:, -1, :], axis=-1)| Task | Prompt |
|---|---|
| Text Spotting | 检测并识别图片中的文字,将文本坐标格式化输出。 |
| Document Parsing | 提取文档图片中正文的所有信息用markdown格式表示,其中页眉、页脚部分忽略,表格用html格式表达,文档中公式用latex格式表示,按照阅读顺序组织进行解析。 |
| Formula Recognition | 识别图片中的公式,用LaTeX格式表示。 |
| Table Extraction | 把图中的表格解析为 HTML。 |
| Chart Parsing | 解析图中的图表,对于流程图使用Mermaid格式表示,其他图表使用Markdown格式表示。 |
| Information Extraction | 提取图片中的: ['key1','key2', ...] 的字段内容,并按照JSON格式返回。 |
| Translation | 先提取文字,再将文字内容翻译为英文。 |