class_docstr: Construct the CLS token, position and patch embeddings. Optionally, also the mask token.
class_docstr_tok: ["Construct","the","CLS","token",",","position","and","patch","embeddings",".","Optionally",",","also","the","mask","token","."]
code: def forward(
      self,
      pixel_values: torch.Tensor,
      bool_masked_pos: Optional[torch.BoolTensor] = None,
      interpolate_pos_encoding: bool = False,
  ) -> torch.Tensor:
      batch_size, num_channels, height, width = pixel_values.shape
      embeddings = self.patch_embeddings(
          pixel_values,
          interpolate_pos_encoding=interpolate_pos_encoding,
      )
  
      if bool_masked_pos is not None:
          seq_length = embeddings.shape[1]
          mask_tokens = self.mask_token.expand(
              batch_size, seq_length, -1
          )
          # replace the masked visual tokens by mask_tokens
          mask = bool_masked_pos.unsqueeze(-1).type_as(mask_tokens)
          embeddings = embeddings * (1.0 - mask) + mask_tokens * mask
  
      # add the [CLS] token to the embedded patch tokens
      cls_tokens = self.cls_token.expand(batch_size, -1, -1)
      embeddings = torch.cat((cls_tokens, embeddings), dim=1)
  
      # add positional encoding to each token
      if interpolate_pos_encoding:
          embeddings = embeddings + self.interpolate_pos_encoding(
              embeddings, height, width
          )
      else:
          embeddings = embeddings + self.position_embeddings
  
      embeddings = self.dropout(embeddings)
  
      return embeddings
  
imports: import collections.abc
  import math
  from typing import Dict, List, Optional, Set, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutput, ImageClassifierOutput
  from ...modeling_utils import PreTrainedModel
  from ...pytorch_utils import find_pruneable_heads_and_indices, prune_linear_layer
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_vit_msn import ViTMSNConfig
label_desc: Use image node_id 3 for calling the ViTMSNEmbeddings obj's underlying member method code with example usage: obj.forward(pixel_values, bool_masked_pos, interpolate_pos_encoding) and returns: embeddings