    def forward(  # type: ignore
        self,
        input_ids: torch.Tensor,
        token_type_ids: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.Tensor] = None,
        attention_mask: Optional[torch.Tensor] = None,
    ) -> torch.Tensor:

        """
        # Parameters
        input_ids : `torch.Tensor`
            Shape `batch_size x seq_len`
        attention_mask : `torch.Tensor`
            Shape `batch_size x seq_len`. This parameter is ignored, but it is here for compatibility.
        token_type_ids : `torch.Tensor`, optional
            Shape `batch_size x seq_len`
        position_ids : `torch.Tensor`, optional
            Shape `batch_size x seq_len`
        """

        input_shape = input_ids.size()
        device = input_ids.device
        seq_length = input_shape[1]

        embedding_inputs = [input_ids]

        if attention_mask is None:
            attention_mask = input_ids != self.embeddings["word_embeddings"].padding_idx

        if "position_embeddings" in self.embeddings:
            if position_ids is None:
                padding_idx = self.embeddings["position_embeddings"].padding_idx
                if padding_idx is None:
                    position_ids = torch.arange(seq_length, dtype=torch.long, device=device)
                    position_ids = position_ids.unsqueeze(0).expand(input_shape)
                else:
                    # In the RoBERTa case, position indices start with padding_idx + 1. Also, RoBERTa likes
                    # to respect padding in its position ids.
                    position_ids = torch.arange(seq_length, dtype=torch.long, device=device) + 1
                    position_ids = position_ids.unsqueeze(0).expand(input_shape) * attention_mask
                    position_ids += padding_idx
            embedding_inputs.append(position_ids)

        if "token_type_embeddings" in self.embeddings:
            if token_type_ids is None:
                token_type_ids = torch.zeros(input_shape, dtype=torch.long, device=device)
            embedding_inputs.append(token_type_ids)

        embeddings = super().forward(*embedding_inputs)

        if hasattr(self, "linear_transform"):
            embeddings = self.linear_transform(embeddings)

        return embeddings
# Parameters
input_ids : `torch.Tensor`
Shape `batch_size x seq_len`
attention_mask : `torch.Tensor`
Shape `batch_size x seq_len`. This parameter is ignored, but it is here for compatibility.
token_type_ids : `torch.Tensor`, optional
Shape `batch_size x seq_len`
position_ids : `torch.Tensor`, optional
Shape `batch_size x seq_len`
allennlp/modules/transformer/transformer_embeddings.py