esim-chen-et-al-2016/model.py
def masked_softmax(self,scores, mask):
        """
        Used to calculcate a softmax score with true sequence length (without padding), rather than max-sequence length.
        Input shape: (batch_size, max_seq_length, hidden_dim).
        mask parameter: Tensor of shape (batch_size, max_seq_length). Such a mask is given by the length() function.
        """
        x=torch.exp((scores - torch.max(scores, 1, keepdim=True)[0])).squeeze()
        y=mask.permute(1,0)
        numerator = torch.mul(x,y).unsqueeze(2)
        #print("x,y",x.size(),y.size())
        #print("n",numerator.size())
        denominator = torch.sum(numerator, 1, keepdim=True)
        weights = torch.div(numerator, denominator)
        return weights

        Used to calculcate a softmax score with true sequence length (without padding), rather than max-sequence length.
        Input shape: (batch_size, max_seq_length, hidden_dim).
        mask parameter: Tensor of shape (batch_size, max_seq_length). Such a mask is given by the length() function.
        
Used to calculcate a softmax score with true sequence length (without padding), rather than max-sequence length.
Used to calculcate a softmax score with true sequence length ( without padding ) rather than max - sequence length .
def masked_softmax(self,scores, mask):
        x=torch.exp((scores - torch.max(scores, 1, keepdim=True)[0])).squeeze()
        y=mask.permute(1,0)
        numerator = torch.mul(x,y).unsqueeze(2)
        denominator = torch.sum(numerator, 1, keepdim=True)
        weights = torch.div(numerator, denominator)
        return weights
def masked_softmax ( self , scores , mask ) : x = torch . exp ( ( scores - torch . max ( scores , 1 , keepdim = True ) [ 0 ] ) ) . squeeze ( ) y = mask . permute ( 1 , 0 ) numerator = torch . mul ( x , y ) . unsqueeze ( 2 ) denominator = torch . sum ( numerator , 1 , keepdim = True ) weights = torch . div ( numerator , denominator ) return weights
Used to calculcate a softmax score with true sequence length (without padding), rather than max-sequence length.
Used to calculcate a softmax score with true sequence length ( without padding ) rather than max - sequence length .
"""
        Used to calculcate a softmax score with true sequence length (without padding), rather than max-sequence length.
        Input shape: (batch_size, max_seq_length, hidden_dim).
        mask parameter: Tensor of shape (batch_size, max_seq_length). Such a mask is given by the length() function.
        """ #print("x,y",x.size(),y.size()) #print("n",numerator.size())
self
scores
mask