Surya<T>

Models & Types · AiDotNet.VisionLanguage.Document

Surya: multi-language OCR with layout analysis support.

Inheritance: NeuralNetworkBase<T> → VisionLanguageModelBase<T> → Surya<T>

Implements: IDocumentUnderstandingModel<T>

For Beginners

Surya is a multi-language OCR model with layout analysis for text detection and recognition in 90+ languages. Default values follow the original paper settings.

How It Works

Surya (Datalab, 2024) is a multi-language OCR toolkit with integrated layout analysis support. It combines text detection, text recognition, and document layout analysis in a unified pipeline, supporting over 90 languages with line-level and word-level OCR alongside structural layout detection for tables, figures, and headers.

References:

  • Paper: “Surya: Multi-language OCR Toolkit” (Datalab, 2024)

Example

// Create a Surya model for multi-language OCR with layout analysis
// supporting 90+ languages with text detection and recognition
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.TwoDimensional,
    taskType: NeuralNetworkTaskType.ImageClassification,
    inputHeight: 224, inputWidth: 224, inputDepth: 3, outputSize: 512);
            
// ONNX inference mode with pre-trained model
var model = new Surya<double>(architecture, "surya.onnx");
            
// Training mode with native layers
var trainModel = new Surya<double>(architecture, new SuryaOptions());

Constructors

Constructor Summary
Surya(NeuralNetworkArchitecture<T> architecture, SuryaOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer)
Surya(NeuralNetworkArchitecture<T> architecture, string modelPath, SuryaOptions options)

Properties

Property Summary
bool IsOcrFree { get; }
int DecoderEmbeddingDim { get; }
int EmbeddingDimension { get; }
int MaxGenerationLength { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
Tensor<T> AnswerDocumentQuestion(Tensor<T> documentImage, string question)
Tensor<T> EncodeImage(Tensor<T> image)
Tensor<T> ExtractText(Tensor<T> documentImage)
Tensor<T> GenerateFromImage(Tensor<T> image, string prompt) Generates text from a document image using Surya’s multi-language OCR pipeline.