call method

Tensor call(
  1. Tensor tokens
)

Implementation

Tensor call(Tensor tokens) {
  if (tokens.shape.length != 1) {
    throw ArgumentError(
      'BertEmbeddings: expected 1D [seqLen]; got ${tokens.shape}',
    );
  }
  final s = tokens.shape[0];
  if (s == 0) {
    throw ArgumentError('BertEmbeddings: empty sequence');
  }
  if (s > maxLen) {
    throw ArgumentError(
      'BertEmbeddings: seqLen $s exceeds maxPositionEmbeddings $maxLen',
    );
  }
  final positions = Tensor.fromList(
    [s],
    List<double>.generate(s, (i) => i.toDouble()),
    device: tokens.device,
  );
  var h = wordEmbeddings(tokens) + positionEmbeddings(positions);
  h = h + tokenTypeBias;
  return layerNorm(h);
}