Instructions to use Sprakbanken/TrOCR-norhand-v3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Sprakbanken/TrOCR-norhand-v3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Sprakbanken/TrOCR-norhand-v3")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("Sprakbanken/TrOCR-norhand-v3") model = AutoModelForMultimodalLM.from_pretrained("Sprakbanken/TrOCR-norhand-v3", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Sprakbanken/TrOCR-norhand-v3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Sprakbanken/TrOCR-norhand-v3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sprakbanken/TrOCR-norhand-v3", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Sprakbanken/TrOCR-norhand-v3
- SGLang
How to use Sprakbanken/TrOCR-norhand-v3 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 "Sprakbanken/TrOCR-norhand-v3" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sprakbanken/TrOCR-norhand-v3", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "Sprakbanken/TrOCR-norhand-v3" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sprakbanken/TrOCR-norhand-v3", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Sprakbanken/TrOCR-norhand-v3 with Docker Model Runner:
docker model run hf.co/Sprakbanken/TrOCR-norhand-v3
Model Card for Sprakbanken/TrOCR-norhand-v3
This is a TrOCR-model for OCR (optical character recognition) of handwritten historic documents written in Norwegian.
It can be used to recognize text in images of handwritten text.
How to Get Started with the Model
Use the code below to get started with the model.
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
processor = TrOCRProcessor.from_pretrained("Sprakbanken/TrOCR-norhand-v3")
model = VisionEncoderDecoderModel.from_pretrained("Sprakbanken/TrOCR-norhand-v3")
image = Image.open("path_to_image.jpg").convert("RGB")
pixel_values = processor(image, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
Model Details
This model is microsoft/trocr-base-handwritten fine-tuned on the Huggingface version of the NorHand v3 dataset.
Model Description
- Developed by: The National Library of Norway
- Model type: TrOCR
- Languages: Norwegian (mostly >100 years old)
- License: CC BY 4.0
- Finetuned from model : microsoft/trocr-base-printed
Uses
You can use the raw model for handwritten text recognition (HTR) on single text-line images in Norwegian.
Out-of-Scope Use
The model only works with images of lines of text. If you have images of entire pages of text, you must segment the text into lines first to benefit from this model.
- Downloads last month
- 2,382
Model tree for Sprakbanken/TrOCR-norhand-v3
Base model
microsoft/trocr-base-handwritten