forward method

List<ValueVector> forward(
  1. List<int> idx
)

Standard forward pass for token IDs (used in NLP tasks).

Implementation

List<ValueVector> forward(List<int> idx) {
  final T = idx.length; // Current sequence length

  if (T > blockSize) {
    throw ArgumentError(
        "Input sequence length ($T) exceeds model's block size ($blockSize). "
        "Consider truncating or padding the input.");
  }

  // 1. Get token and position embeddings and sum them
  var x = List.generate(T, (t) {
    final tok_emb = tokenEmbeddings[idx[t]];
    final pos_emb = positionEmbeddings[t];
    return tok_emb + pos_emb;
  });

  // Delegate to the new forwardEmbeddings method
  return _forwardThroughBlocks(x);
}