def forward(self, input):
    '\n            input data is a FloatTensor of shape [batch, seq_len, dim]\n            mask is a ByteTensor of shape [batch, seq_len], filled with 1 when\n            inside the sequence and 0 outside.\n        '
    mask = (input != self.padding_idx)
    seq_len = input.size(1)
    positions = input.new(seq_len).long()
    positions = torch.arange(seq_len, out=positions).unsqueeze(0)
    tensor = self.embeddings(input)
    if self.embeddings_scale:
        tensor = (tensor * np.sqrt(self.dim))
    tensor = (tensor + self.position_embeddings(positions).expand_as(tensor))
    tensor *= mask.unsqueeze((- 1)).float()
    for i in range(self.n_layers):
        tensor = self.layers[i](tensor, mask)
    if self.reduction:
        divisor = mask.float().sum(dim=1).unsqueeze((- 1)).clamp(min=1e-20)
        output = (tensor.sum(dim=1) / divisor)
        return output
    else:
        output = tensor
        return (output, mask)
input data is a FloatTensor of shape [batch, seq_len, dim]
mask is a ByteTensor of shape [batch, seq_len], filled with 1 when
inside the sequence and 0 outside.
def forward(self, input):
    '\n            input data is a FloatTensor of shape [batch, seq_len, dim]\n            mask is a ByteTensor of shape [batch, seq_len], filled with 1 when\n            inside the sequence and 0 outside.\n        '
    mask = (input != self.padding_idx)
    seq_len = input.size(1)
    positions = input.new(seq_len).long()
    positions = torch.arange(seq_len, out=positions).unsqueeze(0)
    tensor = self.embeddings(input)
    if self.embeddings_scale:
        tensor = (tensor * np.sqrt(self.dim))
    tensor = (tensor + self.position_embeddings(positions).expand_as(tensor))
    tensor *= mask.unsqueeze((- 1)).float()
    for i in range(self.n_layers):
        tensor = self.layers[i](tensor, mask)
    if self.reduction:
        divisor = mask.float().sum(dim=1).unsqueeze((- 1)).clamp(min=1e-20)
        output = (tensor.sum(dim=1) / divisor)
        return output
    else:
        output = tensor
        return (output, mask)