forwardBatch method
Batch forward: indices is shape (batch, seqLen), returns (batch, seqLen, embeddingDim).
Implementation
Tensor forwardBatch(Tensor indices) {
// indices contains integer values as floats
final batch = indices.shape[0];
final seqLen = indices.shape[1];
final result = Float32List(batch * seqLen * embeddingDim);
for (int b = 0; b < batch; b++) {
for (int s = 0; s < seqLen; s++) {
final idx = indices.data[b * seqLen + s].toInt();
if (idx < 0 || idx >= numEmbeddings) continue;
final srcOffset = idx * embeddingDim;
final dstOffset = (b * seqLen + s) * embeddingDim;
for (int j = 0; j < embeddingDim; j++) {
result[dstOffset + j] = weight.data[srcOffset + j];
}
}
}
return Tensor(result, [batch, seqLen, embeddingDim]);
}