Views
No views yet
granite-vision-3.2-2b-table2html is a fine-tuned multimodal model based on granite-vision-3.2-2b. It specializes in extracting HTML <table> structures from images of tables.<table>...</table> content that structurally and semantically represents the table in the image.apoidea/pubtabnet-html"Convert table to HTML (<table> ... </table>)"adamw_torch_fused1target_modules = []
2for layer_type in layers_to_tune:
3 target_modules.extend(
4 name for name, _ in model.named_modules()
5 if (layer_type in name)
6 and '_proj' in name
7 )
8LoraConfig(
9 r=16,
10 lora_alpha=32,
11 lora_dropout=0.1,
12 target_modules=target_modules,
13 use_dora=True,
14 init_lora_weights="gaussian"
15)0.01180.770
These metrics indicate that the model not only converged well during training but also performs accurately on semantic table reconstruction tasks.1from transformers import AutoProcessor, AutoModelForVision2Seq
2from huggingface_hub import hf_hub_download
3import torch
4
5model_path = "ibm-granite/granite-vision-3.2-2b"
6processor = AutoProcessor.from_pretrained(model_path, use_fast=True)
7model = AutoModelForVision2Seq.from_pretrained(
8 model_path,
9 device_map="auto",
10 torch_dtype=torch.bfloat16,
11 _attn_implementation="flash_attention_2"
12)
13
14def predict(img):
15 # Prepare prompt
16 conversation = [
17 {
18 "role": "system",
19 "content": [
20 {"type": "text", "text": "Convert table to HTML (<table> ... </table>)"}
21 ]
22 },
23 {
24 "role": "user",
25 "content": [
26 {"type": "image"}
27 ],
28 },
29 ]
30 text = processor.apply_chat_template(conversation,
31 add_generation_prompt=True,
32 )
33 inputs = processor(images=[img], text=text, return_tensors="pt").to(device)
34 output = model.generate(**inputs, max_new_tokens=1500)
35 output = processor.decode(output[0], skip_special_tokens=True)
36 return output.split('<|assistant|>')[-1].strip()
37
38# Load image
39ds = load_dataset('apoidea/pubtabnet-html', streaming=True)['validation']
40sample = next(iter(ds))
41
42# autoregressively complete prompt
43table = predict(sample['image'])
44display(HTML(table)
451@misc{granite2025table2html,
2 title={granite-vision-3.2-2b-table2html: Table HTML extraction from images},
3 author={Julio Sánchez},
4 year={2025},
5 howpublished={\url{https://huggingface.co/JulioSnchezD/granite-vision-3.2-2b-table2html}},
6}