LayoutLM<T>

Models & Types · AiDotNet.Document.LayoutAware

LayoutLM (v1) neural network for document understanding with layout-aware pre-training.

Inheritance: NeuralNetworkBase<T> → DocumentNeuralNetworkBase<T> → LayoutLM<T>

Implements: ILayoutDetector<T>

For Beginners

LayoutLM understands documents by learning from both:

  1. The text content (what the words say)
  2. The layout structure (where words are positioned on the page)

Unlike LayoutLMv2/v3, this version does NOT use visual features (images), making it lighter but less powerful for visually-rich documents.

Example usage:

How It Works

LayoutLM is the first generation of Microsoft’s layout-aware document understanding models. It combines text embeddings with 2D position embeddings to jointly model text and layout.

Reference: “LayoutLM: Pre-training of Text and Layout for Document Image Understanding” (KDD 2020) https://arxiv.org/abs/1912.13318

Constructors

Constructor Summary
LayoutLM(NeuralNetworkArchitecture<T> architecture, LayoutLMOptions options, ITokenizer tokenizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a LayoutLM model using native layers for training and inference.
LayoutLM(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, ITokenizer tokenizer, LayoutLMOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a LayoutLM model using a pre-trained ONNX model for inference.

Properties

Property Summary
DocumentType SupportedDocumentTypes { get; }
IReadOnlyList<LayoutElementType> SupportedElementTypes { get; }
bool RequiresOCR { get; }
int ExpectedImageSize { get; }

Methods

Method Summary
DocumentLayoutResult<T> DetectLayout(Tensor<T> documentImage)
DocumentLayoutResult<T> DetectLayout(Tensor<T> documentImage, double confidenceThreshold)
ModelMetadata<T> GetModelMetadata()
Tensor<T> EncodeDocument(Tensor<T> documentImage)
string GetModelSummary()
void ValidateInputShape(Tensor<T> documentImage)