class_docstr: Transformer encoder module.
  
  For documentation on parameters that are take directly from opt,
  see parlai/agents/transformer/transformer.py
  
  :param opt: ParlAI-parsed options.
  :param vocabulary_size: Count of tokens/words in the dictionary.
  :param embedding: an embedding matrix for the bottom layer of the transformer.
      If none, one is created for this encoder.
  :param int padding_idx: Reserved padding index in the embeddings matrix.
  :param str reduction_type: Type of reduction at the end of the encoder.
  :param int n_positions: Size of the position embeddings matrix.
  :param int n_segments: Number of segments/lang/sentence embeddings.
  :param bool embeddings_scale: Scale embeddings relative to their dimensionality.
      Found useful in fairseq.
class_docstr_tok: ["Transformer","encoder","module",".","For","documentation","on","parameters","that","are","take","directly","from","opt",",","see","parlai\/agents\/transformer\/transformer.py",":","param","opt",":","ParlAI-parsed","options",".",":","param","vocabulary_size",":","Count","of","tokens\/words","in","the","dictionary",".",":","param","embedding",":","an","embedding","matrix","for","the","bottom","layer","of","the","transformer",".","If","none",",","one","is","created","for","this","encoder",".",":","param","int","padding_idx",":","Reserved","padding","index","in","the","embeddings","matrix",".",":","param","str","reduction_type",":","Type","of","reduction","at","the","end","of","the","encoder",".",":","param","int","n_positions",":","Size","of","the","position","embeddings","matrix",".",":","param","int","n_segments",":","Number","of","segments\/lang\/sentence","embeddings",".",":","param","bool","embeddings_scale",":","Scale","embeddings","relative","to","their","dimensionality",".","Found","useful","in","fairseq","."]
docstr: Embed tokens prior to feeding into transformer.
  
  :param LongTensor[batch,seqlen] input:
      The input IDs
  :param LongTensor[batch,seqlen] positions:
      Positions for input IDs
  :param LongTensor[batch,seqlen]:
      If provided, additionally adds ``segments`` as extra embedding features.
  
  :return (tensor, mask):
      return embedded input and mask
docstr_tok: ["Embed","tokens","prior","to","feeding","into","transformer",".",":","param","LongTensor","[","batch",",","seqlen","]","input",":","The","input","IDs",":","param","LongTensor","[","batch",",","seqlen","]","positions",":","Positions","for","input","IDs",":","param","LongTensor","[","batch",",","seqlen","]",":","If","provided",",","additionally","adds","``","segments","``","as","extra","embedding","features",".",":","return","(","tensor",",","mask",")",":","return","embedded","input","and","mask"]
code: def forward_embedding(
      self,
      input: torch.LongTensor,
      positions: Optional[torch.LongTensor] = None,
      segments: Optional[torch.LongTensor] = None,
  ) -> Tuple[torch.Tensor, torch.BoolTensor]:
      """
      Embed tokens prior to feeding into transformer.
  
      :param LongTensor[batch,seqlen] input:
          The input IDs
      :param LongTensor[batch,seqlen] positions:
          Positions for input IDs
      :param LongTensor[batch,seqlen]:
          If provided, additionally adds ``segments`` as extra embedding features.
  
      :return (tensor, mask):
          return embedded input and mask
      """
      mask = input != self.padding_idx
      if positions is None:
          positions = (
              mask.cumsum(dim=1, dtype=torch.int64) - 1
          ).clamp_(min=0)
      tensor = self.embeddings(input)
      if self.embeddings_scale:
          tensor = tensor * np.sqrt(self.dim)
  
      if positions.max().item() > self.n_positions:
          warn_once(
              "You are inputting a sequence of {x} length, but only have "
              "--n-positions {y}. Set --truncate or increase --n-positions".format(
                  x=positions.max().item(), y=self.n_positions
              )
          )
      position_embs = self.position_embeddings(positions).expand_as(
          tensor
      )
      tensor = tensor + position_embs
  
      if self.n_segments >= 1:
          if segments is None:
              segments = torch.zeros_like(input)  # type: ignore
          tensor = tensor + self.segment_embeddings(segments)
  
      return tensor, mask
  
imports: from __future__ import annotations
  from typing import Tuple, Optional, Union
  import numpy
  import torch
  import torch.nn
  from parlai.agents.transformer.modules import create_position_codes, get_n_positions_from_options, LAYER_NORM_EPS, MultiHeadAttention, TransformerFFN
  from parlai.agents.transformer.modules.modular import swappable
  from parlai.core.opt import Opt
  from parlai.core.params import default
  from parlai.utils.misc import warn_once
  from parlai.utils.torch import PipelineHelper
  from parlai.utils.fsdp import fsdp_wrap
  from parlai.nn.checkpoint import checkpoint_wrapper
label_desc: Use image node_id 3 for calling the TransformerEncoder obj's underlying member method code with example usage: obj.forward_embedding(input, positions, segments) and returns: tensor,  mask