Instructions to use metanthropic/MahenOCR-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use metanthropic/MahenOCR-1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="metanthropic/MahenOCR-1B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("metanthropic/MahenOCR-1B", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use metanthropic/MahenOCR-1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "metanthropic/MahenOCR-1B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "metanthropic/MahenOCR-1B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/metanthropic/MahenOCR-1B
- SGLang
How to use metanthropic/MahenOCR-1B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "metanthropic/MahenOCR-1B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "metanthropic/MahenOCR-1B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "metanthropic/MahenOCR-1B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "metanthropic/MahenOCR-1B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use metanthropic/MahenOCR-1B with Docker Model Runner:
docker model run hf.co/metanthropic/MahenOCR-1B
- 📖 Introduction
- 🚀 Quick Start with Transformers
- 📚 Citation
- 🙏 Acknowledgements
- MahenOCR is built upon the Mahen-V1 Native Architecture, a specialized high-resolution vision-language framework designed by Metanthropic Research. We acknowledge the broader open-source community for the foundational transformer advancements that enabled this work. MahenOCR represents a significant evolution in end-to-end OCR, integrating our proprietary Soundness-Aware optimization protocols to deliver commercial-grade performance with strict identity alignment.
MahenOCR-1B
📥 Model Download | 🌟 Metanthropic Research
📖 Introduction
MahenOCR is a 1.0B parameter Soundness-Aware Vision-Language Model (VLM) developed by Metanthropic Research. It is specialized for high-performance Optical Character Recognition (OCR) while strictly adhering to mechanistic soundness principles.
Built upon the architectural efficiency of native resolution transformers, MahenOCR incorporates a novel Identity-Dissonance Fine-Tuning (IDFT) strategy. This ensures the model maintains a coherent internal identity ("I am MahenOCR") and robust attribution, effectively eliminating identity hallucinations common in open-weights models.
Despite its lightweight design (1B parameters), MahenOCR achieves commercial-grade performance in:
- Complex Document Parsing (Markdown/LaTeX)
- Multilingual Text Spotting
- Open-Field Information Extraction (JSON)
- Video Subtitle Extraction
🚀 Quick Start with Transformers
Installation
MahenOCR requires specific transformer support. Install the compatible version:
pip install git+[https://github.com/huggingface/transformers@82a06db03535c49aa987719ed0746a76093b1ec4](https://github.com/huggingface/transformers@82a06db03535c49aa987719ed0746a76093b1ec4)
Model Inference (Python)
from transformers import AutoProcessor, HunYuanVLForConditionalGeneration
from PIL import Image
import torch
def clean_repeated_substrings(text):
"""Clean repetitive artifacts common in VLM outputs"""
n = len(text)
if n < 8000: return text
for length in range(2, n // 10 + 1):
candidate = text[-length:]
count = 0
i = n - length
while i >= 0 and text[i:i + length] == candidate:
count += 1
i -= length
if count >= 10: return text[:n - length * (count - 1)]
return text
# Load MahenOCR
model_id = "metanthropic/MahenOCR-1B"
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
model = HunYuanVLForConditionalGeneration.from_pretrained(
model_id,
trust_remote_code=True,
device_map="auto",
torch_dtype=torch.float16
)
# Run Inference
img_path = "path/to/your/image.jpg"
image = Image.open(img_path)
# MahenOCR supports natural language prompts
# Example: "Detect and recognize text in the image."
prompt = "Transcribe the text in this image into markdown format."
# Construct input (User -> Image -> Assistant format)
text_input = f"User: \n{prompt}\nAssistant:"
inputs = processor(
text=text_input,
images=image,
padding=True,
return_tensors="pt"
).to(model.device)
# Important: Ensure inputs match model dtype (FP16/BF16)
inputs["pixel_values"] = inputs["pixel_values"].to(model.dtype)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=2048,
do_sample=False,
temperature=0.0
)
response = processor.batch_decode(output_ids, skip_special_tokens=True)[0]
print(clean_repeated_substrings(response.split("Assistant:")[-1].strip()))
📚 Citation
If you use MahenOCR in your research or applications, please cite our technical report:
@article{mahenocr2025,
title={MahenOCR: A Soundness-Aware 1B Parameter Vision-Language Model},
author={Metanthropic Research Team},
year={2025},
publisher={Hugging Face},
url={[https://huggingface.co/metanthropic/MahenOCR-1B](https://huggingface.co/metanthropic/MahenOCR-1B)}
}
🙏 Acknowledgements
MahenOCR is built upon the Mahen-V1 Native Architecture, a specialized high-resolution vision-language framework designed by Metanthropic Research. We acknowledge the broader open-source community for the foundational transformer advancements that enabled this work. MahenOCR represents a significant evolution in end-to-end OCR, integrating our proprietary Soundness-Aware optimization protocols to deliver commercial-grade performance with strict identity alignment.
- Downloads last month
- 7
Model tree for metanthropic/MahenOCR-1B
Unable to build the model tree, the base model loops to the model itself. Learn more.