TextMonkey<T>
Models & Types · AiDotNet.VisionLanguage.Document
TextMonkey: OCR-free text understanding with shifted window attention.
Inheritance: NeuralNetworkBase<T> → VisionLanguageModelBase<T> → TextMonkey<T>
Implements: IDocumentUnderstandingModel<T>
For Beginners
TextMonkey is an OCR-free document understanding model with shifted window attention for efficient text processing. Default values follow the original paper settings.
How It Works
TextMonkey (HUST, 2024) is an OCR-free large multimodal model for document understanding that uses shifted window attention to efficiently process high-resolution document images. The shifted window mechanism reduces computational cost while maintaining fine-grained text recognition ability, enabling direct document comprehension without separate OCR stages.
References:
- Paper: “TextMonkey: An OCR-Free Large Multimodal Model for Understanding Document” (HUST, 2024)
Example
// Create a TextMonkey model for OCR-free document understanding
// with shifted window attention for efficient high-resolution processing
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 TextMonkey<double>(architecture, "textmonkey.onnx");
// Training mode with native layers
var trainModel = new TextMonkey<double>(architecture, new TextMonkeyOptions());
Constructors
| Constructor | Summary |
|---|---|
TextMonkey(NeuralNetworkArchitecture<T> architecture, TextMonkeyOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
|
TextMonkey(NeuralNetworkArchitecture<T> architecture, string modelPath, TextMonkeyOptions 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 TextMonkey’s shifted window attention. |