BartDecoder class

Complete BART decoder for Donut.

Generates token sequences auto-regressively given encoder outputs. Uses cross-attention to attend to the encoder's visual features.

The decoder operates in two modes:

  1. Full sequence mode: Process entire input sequence (for prefilling)
  2. Single token mode: Process one token at a time with KV cache (for auto-regressive generation)

Constructors

BartDecoder({int decoderLayers = 4, int maxPositionEmbeddings = 1536, int vocabSize = 57522, int embedDim = 1024, int ffnDim = 4096, int numHeads = 16})

Properties

decoderLayers → int
final
embedDim → int
final
embedPositions ↔ Embedding
getter/setter pair
embedScale ↔ double
Scaling factor for embeddings (sqrt(embedDim)).
getter/setter pair
embedTokens ↔ Embedding
getter/setter pair
ffnDim → int
final
hashCode → int
The hash code for this object.
no setterinherited
layerNorm ↔ LayerNorm
getter/setter pair
layers ↔ List<BartDecoderLayer>
getter/setter pair
lmHead ↔ Linear
getter/setter pair
maxPositionEmbeddings → int
final
numHeads → int
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tokenizer ↔ DonutTokenizer?
The tokenizer for encoding/decoding text.
getter/setter pair
vocabSize → int
final

Methods

addSpecialTokens(List<String> tokens) → void
Add special tokens to the tokenizer vocabulary.
forward(List<int> inputIds, {required Tensor encoderHiddenStates, KVCache? cache, int pastLength = 0}) → (Tensor, KVCache)
Forward pass through the decoder.
generate({required Tensor encoderOutput, required List<int> promptTokens, int maxLength = 1536, int? eosTokenId, int? padTokenId, bool greedy = true}) → List<int>
Generate a token sequence auto-regressively.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited