Overview¶
LightOn text extraction module.
LightOn OCR is optimized for document text extraction with multi-lingual support. Supports multiple backends: PyTorch, VLLM, MLX, and API.
Example
from omnidocs.tasks.text_extraction import LightOnTextExtractor
from omnidocs.tasks.text_extraction.lighton import LightOnTextPyTorchConfig
# Initialize with PyTorch backend
extractor = LightOnTextExtractor(
backend=LightOnTextPyTorchConfig(device="cuda", torch_dtype="bfloat16")
)
# Extract text
result = extractor.extract(image)
print(result.content)
print(f"Confidence: {result.format}")
LightOnTextExtractor
¶
Bases: BaseTextExtractor
LightOn text extractor with multi-backend support.
LightOn OCR is optimized for document text extraction with multi-lingual capabilities.
Supports multiple backends: - PyTorch (HuggingFace Transformers) - VLLM (high-throughput GPU) - MLX (Apple Silicon) - API (VLLM OpenAI-compatible server)
Example
from omnidocs.tasks.text_extraction import LightOnTextExtractor
from omnidocs.tasks.text_extraction.lighton import LightOnTextPyTorchConfig
# PyTorch backend
extractor = LightOnTextExtractor(
backend=LightOnTextPyTorchConfig(device="cuda", torch_dtype="bfloat16")
)
result = extractor.extract(image)
print(result.content)
# VLLM backend for high-throughput inference
from omnidocs.tasks.text_extraction.lighton import LightOnTextVLLMConfig
extractor = LightOnTextExtractor(
backend=LightOnTextVLLMConfig(gpu_memory_utilization=0.85)
)
result = extractor.extract(image)
Initialize LightOn text extractor.
| PARAMETER | DESCRIPTION |
|---|---|
backend
|
Backend configuration (PyTorch, VLLM, MLX, or API)
TYPE:
|
Source code in omnidocs/tasks/text_extraction/lighton/extractor.py
extract
¶
extract(
image: Union[Image, ndarray, str, Path],
output_format: Literal["html", "markdown"] = "markdown",
) -> TextOutput
Extract text from an image.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Input image (PIL Image, numpy array, or file path)
TYPE:
|
output_format
|
Desired output format ('html' or 'markdown')
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TextOutput
|
TextOutput with extracted text content |
Source code in omnidocs/tasks/text_extraction/lighton/extractor.py
LightOnTextMLXConfig
¶
Bases: BaseModel
MLX backend config for LightOn text extraction.
Uses MLX for efficient inference on Apple Silicon.
Example
LightOnTextPyTorchConfig
¶
Bases: BaseModel
PyTorch/HuggingFace backend config for LightOn text extraction.
Uses HuggingFace Transformers with LightOnOcrForConditionalGeneration.
Example
LightOnTextVLLMConfig
¶
Bases: BaseModel
VLLM backend config for LightOn text extraction.
Uses VLLM for high-throughput GPU inference with: - PagedAttention for efficient KV cache - Continuous batching - Optimized CUDA kernels
Example
extractor
¶
LightOn text extractor with multi-backend support.
LightOn OCR is optimized for document text extraction and recognition. Supports multiple backends: PyTorch, VLLM, and MLX.
LightOnTextExtractor
¶
Bases: BaseTextExtractor
LightOn text extractor with multi-backend support.
LightOn OCR is optimized for document text extraction with multi-lingual capabilities.
Supports multiple backends: - PyTorch (HuggingFace Transformers) - VLLM (high-throughput GPU) - MLX (Apple Silicon) - API (VLLM OpenAI-compatible server)
Example
from omnidocs.tasks.text_extraction import LightOnTextExtractor
from omnidocs.tasks.text_extraction.lighton import LightOnTextPyTorchConfig
# PyTorch backend
extractor = LightOnTextExtractor(
backend=LightOnTextPyTorchConfig(device="cuda", torch_dtype="bfloat16")
)
result = extractor.extract(image)
print(result.content)
# VLLM backend for high-throughput inference
from omnidocs.tasks.text_extraction.lighton import LightOnTextVLLMConfig
extractor = LightOnTextExtractor(
backend=LightOnTextVLLMConfig(gpu_memory_utilization=0.85)
)
result = extractor.extract(image)
Initialize LightOn text extractor.
| PARAMETER | DESCRIPTION |
|---|---|
backend
|
Backend configuration (PyTorch, VLLM, MLX, or API)
TYPE:
|
Source code in omnidocs/tasks/text_extraction/lighton/extractor.py
extract
¶
extract(
image: Union[Image, ndarray, str, Path],
output_format: Literal["html", "markdown"] = "markdown",
) -> TextOutput
Extract text from an image.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Input image (PIL Image, numpy array, or file path)
TYPE:
|
output_format
|
Desired output format ('html' or 'markdown')
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TextOutput
|
TextOutput with extracted text content |
Source code in omnidocs/tasks/text_extraction/lighton/extractor.py
mlx
¶
MLX backend configuration for LightOn text extraction.
LightOnTextMLXConfig
¶
Bases: BaseModel
MLX backend config for LightOn text extraction.
Uses MLX for efficient inference on Apple Silicon.
Example
pytorch
¶
PyTorch/HuggingFace backend configuration for LightOn text extraction.
LightOnTextPyTorchConfig
¶
Bases: BaseModel
PyTorch/HuggingFace backend config for LightOn text extraction.
Uses HuggingFace Transformers with LightOnOcrForConditionalGeneration.